首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Logback:记录器功能不能在控制台中打印消息。

Logback:记录器功能不能在控制台中打印消息。
EN

Stack Overflow用户
提问于 2015-02-04 17:57:08
回答 1查看 1.5K关注 0票数 0

我是个日志新手,并且在我的项目中使用logback。我在maven项目的类路径下创建了记录器配置文件logback.xml,这是在资源根文件夹下。以下是我的配置文件:

代码语言:javascript
复制
<?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代码如下:

代码语言:javascript
复制
private Logger logger = LoggerFactory.getLogger(MachineController.class);
public String machinesList(Model model) {
    logger.info("call machinesList controller GET");
    ---------------------
}

当我启动tomcat时,服务器打印以下日志:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2015-02-04 19:16:14

这是“appender ref”,不是"appernder-ref“。

这就是为什么您的附加器没有注册到root-logger:

代码语言:javascript
复制
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]]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28318396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档