This is my log4j.xml
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<!-- DAILY ROLLING -->
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="MaxFileSize" value="10240KB" />
<!-- Keep one backup file -->
<param name="MaxBackupIndex" value="10" />
<param name="ImmediateFlush" value="true" />
<param name="Append" value="true" />
<param name="File" value="/usr/local/xmld/log/xmld-core.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="XMLD2[%t] [loadId(%X{loadID}) - %X{customer} - %X{configuration} - %X{filename}]: %-5p - %d{yyyy-MM-dd HH:mm:ss,SSS} (%F:%M:%L) %m%n" />
</layout>
</appender>
<!-- SYSLOG -->
<appender name="syslog" class="org.apache.log4j.net.SyslogAppender">
<param name="syslogHost" value="${hostName}" />
<param name="facility" value="LOCAL6" />
<param name="facilityPrinting" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="XMLD2[%t] [loadId(%X{loadID}) - %X{customer} - %X{configuration} - %X{filename}]: %-5p - %d{yyyy-MM-dd HH:mm:ss,SSS} (%F:%M:%L) %m%n" />
</layout>
</appender>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="XMLD2[%t] ${hostName} [loadId(%X{loadID}) - %X{customer} - %X{configuration} - %X{filename}]: %-5p - %d{yyyy-MM-dd HH:mm:ss,SSS} (%F:%M:%L) %m%n" />
<!-- %d (%c{1})[%5p] %m%n -->
</layout>
</appender>
<!-- ====== Categories ===== -->
<!-- core -->
<logger name="com.my.xmldelivery2.core">
<level value="DEBUG" />
<appender-ref ref="syslog" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</logger>
<logger name="com.my.commons.utils">
<level value="DEBUG" />
<appender-ref ref="syslog" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</logger>
<!-- hibernate -->
<logger name="org.hibernate">
<level value="INFO" />
<appender-ref ref="syslog" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</logger>
<!-- Apache VFS2 -->
<logger name="org.apache.commons.vfs2">
<level value="INFO" />
<appender-ref ref="syslog" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</logger>
The package com.my.commons.utils
is a dependency whereas com.my.xmldelivery2.core
is my software. This is the log4j.xml generated after maven install
.
But in the console log I can't see anything about the utils package. The package name is correct. I really don't understand what I'm doing wrong. I have to say that the last two packages are also used in the first two packages.
try this:
1) add root logger configuration, all log events are populated to the root:
<root>
<level value="DEBUG" />
<appender-ref ref="syslog" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</root>
2) remove all your DEBUG logger configuration
3) configure just INFO level. DEBUG will not pass up to the root
<!-- hibernate -->
<logger name="org.hibernate">
<level value="INFO" />
</logger>
<!-- Apache VFS2 -->
<logger name="org.apache.commons.vfs2">
<level value="INFO" />
</logger>
First, if the com.my.commons.utils
package is in a dependency, can you tell for sure that the classes in that dependency use loggers by the name of the class name? If com.my.commons.utils.MyClass
is using a logger named MyFancyLogger
, you won't have anything printed.
So, assuming that classes inside the utils
package follow the "logger name matching class name" practice: are any of your Log4J instructions seem to work? Do you know for certain that your log4j.xml
is indeed taking effect?
At any case, you can use the -Dlog4j.debug=true
system property to see exactly what's going on behind the scenes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.