简体   繁体   English

log4j2配置文件未记录到控制台/文件

[英]log4j2 config file not logging to console/file

I have the following log4j2.xml config that I am using. 我有以下正在使用的log4j2.xml配置。 I have 2 issues :- 我有2个问题:-

  1. When my application runs up, I have nothing logged to either the console or to mylog.log file by either of apache or springframework or hibernate classes. 当我的应用程序运行时,apache或springframework或hibernate类都没有将任何日志记录到控制台或mylog.log文件中。

  2. Classes within the package "com.foo.bar", I am able change the log LEVEL via "level" attribute but the messages are only logged to mylog.log file but nothing to the console 包“ com.foo.bar”中的类,我可以通过“ level”属性更改日志级别,但消息仅记录到mylog.log文件中,而没有记录到控制台中

Any suggestions to above would be appreciated ? 以上任何建议将不胜感激?

thank you Pete 谢谢皮特

<Appenders>

    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%d{DEFAULT} [%t] %-5level %logger{36} - %msg%n" />
    </Console>

    <RollingFile name="File" fileName="mylog.log"
        filePattern="mylog-%d{yyyy-MM-dd}.%i.log">
        <PatternLayout pattern="%d{DEFAULT} [%t] %-5level %logger{36} - %msg%n" />
        <Policies>
            <TimeBasedTriggeringPolicy />
            <SizeBasedTriggeringPolicy size="30 MB" />
        </Policies>
    </RollingFile>

</Appenders>

<Loggers>

    <Logger name="com.foo.bar" level="info" additivity="false">
        <AppenderRef ref="File" />
        <AppenderRef ref="Console" />
    </Logger>

    <Logger name="org.apache" level="debug" >
        <AppenderRef ref="File" />
        <AppenderRef ref="Console" />
    </Logger>

    <Logger name="org.hibernate" level="debug" additivity="false">
        <AppenderRef ref="File" />
    </Logger>

    <Logger name="org.springframework" level="debug" additivity="false">
        <AppenderRef ref="File" />
    </Logger>       

    <Root level="all">
        <AppenderRef ref="Console" />
        <AppenderRef ref="File" />
    </Root>

</Loggers>

Please try replacing 请尝试更换

<Root level="all">

With

<Root level="trace">

It sounds like you have a misconfigured log. 听起来您的日志配置错误。

Can you debug remotely and where you find use the logger to log something place a breakpoint. 您可以进行远程调试吗?在哪里可以找到使用记录器记录断点的地方。 Inspect the logger and then you will find a location of where its picking up the log file from. 检查记录器,然后您将找到记录器从中拾取日志文件的位置。

Also try providing a VM argument for log4j configuration (-Dlog4j.configuration)on start-up of your application. 还应尝试在应用程序启动时为log4j配置(-Dlog4j.configuration)提供VM参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM