我要做什么?
我正在使用Logback在Spring Boot应用程序中添加一个记录器。
到目前为止我做了什么?
我在应用程序属性中添加了以下内容
logging.config=classpath:logback-dev.xml
这是我的登录配置
logback-dev.xml
<configuration>
<Appenders>
<!-- Console Appender -->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<!-- File Appender -->
<File name="File"
fileName="D:/logs/myApp.log">
<PatternLayout
pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" />
</File>
<encoder>
<pattern>%d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n</pattern>
</encoder>
</Appenders>
<Loggers>
<logger name="com.test" level="DEBUG"
additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="File" />
</logger>
</Loggers>
</configuration>
在运行应用程序时,出现以下异常。
Logging system failed to initialize using configuration from 'classpath:logback-dev.xml'
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:13 - no applicable action for [Appenders], current ElementPath is [[configuration][Appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:47 - no applicable action for [Console], current ElementPath is [[configuration][Appenders][Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:79 - no applicable action for [PatternLayout], current ElementPath is [[configuration][Appenders][Console][PatternLayout]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:65 - no applicable action for [File], current ElementPath is [[configuration][Appenders][File]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:79 - no applicable action for [PatternLayout], current ElementPath is [[configuration][Appenders][File][PatternLayout]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@15:13 - no applicable action for [encoder], current ElementPath is [[configuration][Appenders][encoder]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:22 - no applicable action for [pattern], current ElementPath is [[configuration][Appenders][encoder][pattern]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@19:11 - no applicable action for [Loggers], current ElementPath is [[configuration][Loggers]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@21:23 - no applicable action for [logger], current ElementPath is [[configuration][Loggers][logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@26:23 - no applicable action for [logger], current ElementPath is [[configuration][Loggers][logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@31:23 - no applicable action for [logger], current ElementPath is [[configuration][Loggers][logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@33:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@36:23 - no applicable action for [logger], current ElementPath is [[configuration][Loggers][logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@41:23 - no applicable action for [logger], current ElementPath is [[configuration][Loggers][logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@42:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@46:23 - no applicable action for [logger], current ElementPath is [[configuration][Loggers][logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@47:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@48:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][logger][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@51:23 - no applicable action for [root], current ElementPath is [[configuration][Loggers][root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@52:33 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][root][AppenderRef]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:30 - no applicable action for [AppenderRef], current ElementPath is [[configuration][Loggers][root][AppenderRef]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:311)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.shc.ecom.ons.listener.OnsListenerApplication.main(OnsListenerApplication.java:15)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:13 - no applicable action for [Appenders], current ElementPath is [[configuration][Appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:47 - no applicable action for [Console], current ElementPath is [[configuration][Appenders][Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:79 - no applicable action for [PatternLayout], current ElementPath is [[configuration][Appenders][Console][PatternLayout]]
我被困在这里,因为我无法弄清楚自己做错了什么。这是我的第一个spring boot应用程序。 供参考,这是我的POM文件
Pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>${spring-kafka.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<artifactId>logback-access</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>ca.pjer</groupId>
<artifactId>logback-awslogs-appender</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>