我是日志记录的新手,并且使用logback
作为我的项目。我在maven项目的类路径中创建了记录器配置文件logback.xml
,它位于资源根文件夹中。以下是我的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>It-Support</contextName>
<timestamp key="timeFormat" datePattern="yyyyMMdd'T'HHmmss" timeReference="contextBirth" />
<property resource="properties/logback-variables.properties" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${file.record}/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>6</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appernder-ref ref="STDOUT" />
<!-- <appernder-ref ref="ROLLING" /> -->
</root>
</configuration>
在我的java代码中,我使用logger.info, logger,error etc
方法在控制台上打印信息,但是当代码运行时,logger无法在eclipse控制台上打印信息。我的java代码如下:
private Logger logger = LoggerFactory.getLogger(MachineController.class);
public String machinesList(Model model) {
logger.info("call machinesList controller GET");
---------------------
}
当我启动tomcat时,服务器打印在下面记录:
SEVERE: The web application [/it-support] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1@31924c14]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [b1d32454-45c4-4684-9339-b12835b563d2-0]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
15:13:00,945 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Could NOT find resource [logback.groovy]
15:13:00,946 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Could NOT find resource [logback-test.xml]
15:13:00,946 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Found resource [logback.xml] at [jar:file:/D:/tommy8/webapps/it-support-web/WEB-INF/lib/it-support-common-0.0.1-SNAPSHOT.jar!/logback.xml]
15:13:01,004 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@20b42477 - URL [jar:file:/D:/tommy8/webapps/it-support-web/WEB-INF/lib/it-support-common-0.0.1-SNAPSHOT.jar!/logback.xml] is not of type file
15:13:01,078 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:13:01,101 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [It-Support]
15:13:01,101 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using context birth as time reference.
15:13:01,107 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="timeFormat" and value="20150204T151300" to the LOCAL scope
15:13:01,111 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:13:01,119 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
15:13:01,165 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:13:01,285 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:13:01,291 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ROLLING]
15:13:01,361 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:13:01,365 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern log-%d{yyyy-MM-dd}.%i.log for the active file
15:13:01,371 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@28345639 - The date pattern is 'yyyy-MM-dd' from file name pattern 'log-%d{yyyy-MM-dd}.%i.log'.
15:13:01,371 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@28345639 - Roll-over at midnight.
15:13:01,372 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@28345639 - Setting initial period to Thu Jan 08 20:09:57 IST 2015
15:13:01,375 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:13:01,381 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLING] - Active log file name: logs/log.log
15:13:01,381 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLING] - File property is set to [logs/log.log]
15:13:01,384 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:13:01,394 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:33 - no applicable action for [appernder-ref], current ElementPath is [[configuration][root][appernder-ref]]
15:13:01,394 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:13:01,397 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@63f55760 - Registering current configuration as safe fallback point
答案 0 :(得分:1)
这是“appender-ref”,而不是“appernder-ref”。
这就是你的appender没有在root-logger注册的原因:
15:13:01,394 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:33 - no applicable action for [appernder-ref], current ElementPath is [[configuration][root][appernder-ref]]