无法在Logback中将追加程序设置为记录器 [英] Fail to set appender to logger in Logback

查看:143
本文介绍了无法在Logback中将追加程序设置为记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个附加文件,并希望将org.springframwork和ch.qos.logback定向到此日志文件.但是,当我在Linux服务器上运行我的应用程序时,这两个软件包的INFO消息不会进入日志文件,而是直接打印出来. 这是我的logback.xml:

I have an appender FILE, and want to direct org.springframwork and ch.qos.logback to this log file. However, when i run my application on linux server, the INFO message for these two packages does not go into the log file, but directly printed out. Here is my logback.xml:

<configuration debug="true">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
<jmxConfigurator/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>log/myfile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>log/myfile.%i.log.gz</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>10</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>500MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%d{ISO8601} %-5p [%t] [%c{1}] - %m%n</pattern>
    </encoder>
</appender>
<root level="${log.level:-INFO}">
    <appender-ref ref="FILE"/>
</root>
<logger name="org.springframework" level="INFO">
    <appender-ref ref="FILE"/>
</logger>
<logger name="ch.qos.logback" level="INFO">
    <appender-ref ref="FILE"/>
</logger>

08:23:22,446 | -INFO在ch.qos.logback.classic.joran.JoranConfigurator@1b83cfe9-将当前配置注册为安全的后备点

08:23:22,446 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@1b83cfe9 - Registering current configuration as safe fallback point

2015年4月9日上午8:23:22 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO:从类路径资源[spring/spring-common.xml]中加载XML bean定义

Apr 09, 2015 8:23:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [spring/spring-common.xml]

有人可以帮我指出我的配置出了什么问题吗?谢谢.

Can someone help point out what is wrong with my configuration? Thank you.

顺便说一句:我从Logback文档中了解到,我不需要为记录器设置相同的appender-ref,否则它将两次打印到相同的appender中.但是我从logback调试信息中看到,仅当我为logger设置appender-ref时,才会为logger设置appender.

BTW: I read from logback documentation that I don't need to set same appender-ref for logger, otherwise it will be printed out into same appender twice. But i see from the logback debug info that only if i set appender-ref for logger, it will set appender for the logger.

推荐答案

使用日志配置无法重定向ch.qos.logback的第一个日志输出,因为此输出在Logback读取其配置时发生->母鸡/鸡蛋风格问题

The first log output by ch.qos.logback can't be redirected using the log configuration because this output happens while Logback reads it's configuration -> hen / egg style problem.

要摆脱这些消息,请在XML中使用debug="false".

To get rid of those messages, use debug="false" in your XML.

org.springframework不会使用Logback.在 http://www.slf4j.org/legacy.htmljcl-over-slf4j.jar >

org.springframework doesn't use Logback unless you install a bridge for org.apache.commons.logging (which is the logging framework used by Spring). Look for jcl-over-slf4j.jar in the documentation at http://www.slf4j.org/legacy.html

这篇关于无法在Logback中将追加程序设置为记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆