SpringBoot 는 사용자 정의 로그 프레임 워 크 를 사용 합 니 다. 로그 저장 방식 은 json 로그 형식 입 니 다.
34764 단어 로그
SpringBoot 는 1.4 이상 버 전부터 log 4 로 그 를 지원 하지 않 고 log4j 2 로 그 를 사용 하기 시 작 했 습 니 다. 사용자 정의 로그 프레임 워 크 를 사용 하려 면 SpringBoot 가 기본적으로 사용 하 는 로 그 를 제외 하고 log4j 2 가 json 로그 형식 을 지원 하 는 지 알려 야 합 니 다.
log4j 2. x 버 전 은 1. x 의. properties 접미사 와 같은 파일 설정 방식 을 지원 하지 않 습 니 다. 2. x 버 전 프로필 접미사 이름 은 'xml', '. json' 또는 '. jsn' 만 지원 합 니 다.
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-loggingartifactId>
exclusion>
exclusions>
dependency>
로그 4j 2 의존 도입
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-log4j2artifactId>
<version>1.5.8.RELEASEversion>
dependency>
.reporting .outputEncoding>UTF-8.reporting.outputEncoding>
.version>1.8 .version>
.level>debug .level>
.root.path>/data/springcloud/logs/xx/config/config .root.path>
.error.path>/data/springcloud/logs/xx/config/config .error.path>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-coreartifactId>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
dependency>
<sourceDirectory>src/main/javasourceDirectory>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<filtering>truefiltering>
<includes>
<include>**/*include>
includes>
resource>
resources>
필요 한 플러그 인 추가
<plugin>
<artifactId>maven-resources-pluginartifactId>
<configuration>
<encoding>utf-8encoding>
<useDefaultDelimiters>trueuseDefaultDelimiters>
configuration>
plugin>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
SpringBoot 프로필 지정 log4j. xml
logging.config=classpath:log4j2.xml
log4j 2. xml 설정: log4j 2 는 레이아웃 방식 이 많 습 니 다. 그 중에서 JosnLayout 는 기록 방식 이 json 방식 임 을 표시 합 니 다.
<configuration status="WARN">
<Properties>
<Property name="pattern">%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%l - %m%nProperty>
Properties>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="console">AppenderRef>
<AppenderRef ref="rolling_file">AppenderRef>
Root>
Loggers>
<Appenders>
<Console name="console" target="SYSTEM_OUT" follow="true">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
Console>
<RollingFile name="rolling_file"
fileName="${log4j2.root.path}.log"
filePattern="${log4j2.root.path}_%d{yyyy-MM-dd}.log">
<JsonLayout/>
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
Policies>
RollingFile>
<File name="file" fileName="${log4j2.package.path}.log">
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
File>
Appenders>
configuration>
다음 오류 가 발생 하면 SpringBoot 가 가지 고 있 는 로그 패 키 지 를 깨끗 한 해결 방법 으로 제거 하 는 것 을 설명 합 니 다.
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-loggingartifactId>
exclusion>
exclusions>
dependency>
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
2018-08-29 14:20:29.261 INFO 13472 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@59474f18: startup date [Wed Aug 29 14:20:29 CST 2018]; root of context hierarchy
2018-08-29 14:20:29.614 INFO 13472 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-08-29 14:20:29.662 INFO 13472 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$738c003a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:17 - no applicable action for [Properties], current ElementPath is [[configuration][Properties]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:34 - no applicable action for [Property], current ElementPath is [[configuration][Properties][Property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:14 - no applicable action for [Loggers], current ElementPath is [[configuration][Loggers]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:29 - no applicable action for [Root], current ElementPath is [[configuration][Loggers][Root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:40 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][Root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:37 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][Root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [Appenders], current ElementPath is [[configuration][Appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@25:67 - no applicable action for [Console], current ElementPath is [[configuration][Appenders][Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:79 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][Appenders][Console][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@57:114 - no applicable action for [File], current ElementPath is [[configuration][Appenders][File]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:80 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][Appenders][File][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@69:61 - no applicable action for [JsonLayout], current ElementPath is [[configuration][Appenders][File][JsonLayout]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at com.yiche.UserApplication2.main(UserApplication2.java:34)
Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:17 - no applicable action for [Properties], current ElementPath is [[configuration][Properties]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:34 - no applicable action for [Property], current ElementPath is [[configuration][Properties][Property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:14 - no applicable action for [Loggers], current ElementPath is [[configuration][Loggers]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:29 - no applicable action for [Root], current ElementPath is [[configuration][Loggers][Root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:40 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][Root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:37 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][Root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [Appenders], current ElementPath is [[configuration][Appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@25:67 - no applicable action for [Console], current ElementPath is [[configuration][Appenders][Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:79 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][Appenders][Console][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@57:114 - no applicable action for [File], current ElementPath is [[configuration][Appenders][File]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:80 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][Appenders][File][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@69:61 - no applicable action for [JsonLayout], current ElementPath is [[configuration][Appenders][File][JsonLayout]]
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:315)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at com.yiche.UserApplication2.main(UserApplication2.java:34)
Caused by: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:17 - no applicable action for [Properties], current ElementPath is [[configuration][Properties]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:34 - no applicable action for [Property], current ElementPath is [[configuration][Properties][Property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:14 - no applicable action for [Loggers], current ElementPath is [[configuration][Loggers]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:29 - no applicable action for [Root], current ElementPath is [[configuration][Loggers][Root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:40 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][Root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:37 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][Root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [Appenders], current ElementPath is [[configuration][Appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@25:67 - no applicable action for [Console], current ElementPath is [[configuration][Appenders][Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:79 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][Appenders][Console][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@57:114 - no applicable action for [File], current ElementPath is [[configuration][Appenders][File]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:80 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][Appenders][File][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@69:61 - no applicable action for [JsonLayout], current ElementPath is [[configuration][Appenders][File][JsonLayout]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308)
... 11 more
Process finished with exit code 1
참고:https://www.cnblogs.com/baizhanshi/p/7503417.html
https://blog.csdn.net/rogger_chen/article/details/50587920
https://blog.csdn.net/zhou_kapenter/article/details/64123933
https://blog.csdn.net/yangzhuangqiu/article/details/49636661
http://book.51cto.com/art/201512/499576.htm
https://blog.csdn.net/wendingzhulu/article/details/52423522
SpringBoot 사용자 정의 log4j 2 로그https://www.cnblogs.com/advancing/p/7922463.html
log4j 2 로그 의 레이아웃 과 APIhttp://logging.apache.org/log4j/log4j-2.2/manual/layouts.html http://logging.apache.org/log4j/2.x/manual/layouts.html#JSONLayout
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
소샤게 CS 워크 플로우 개선 바람 관리 화면 12/16로 투고2020/02/08 구성과 설계를 기재 안녕하세요, 코로나입니다. 이번에는 업무에 가깝지만 가상 포트폴리오를 준비해 보았습니다. 신규 개발팀 백엔드 2명 프런트 x명 기획 2명 운영팀 백엔드 1명 문의 겸 기획 1명...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.