Hello!
I faced with a problem using LogFactory.getLog for logging.
I configure my log4j with DOMConfigurator.configureAndWatch(XMLFile) and then I create an instance of commons.logging.Log
Log log = LogFactory.getLog(className);
After that I try to log:
log.info("I'm a log!");
XMLFile configure log4j to write logs to file (see below).
but the last command writes logs to the specified file and to CONSOLE. Why?
and two more things:
- I've included log4j.jar to the lib of my .ear project - with this I wanted all my project to use one log4j configuration.
- This all is under JBoss AS. And I don't want to use xml file of jboss to configure log4j.
This is my xml config file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration > <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> <appender name="fileappender" class="org.apache.log4j.DailyRollingFileAppender"> <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> <param name="File" value="${jboss.server.home.dir}/log/project.log"/> <param name="Append" value="true"/> <param name="DatePattern" value="'.'yyyy-MM-dd"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> </appender> <category name="some.package"> <priority value="DEBUG" /> <appender-ref ref="fileappender" /> </category> </log4j:configuration>
Problem solved.
I should have added the property additivity to category in xml file - now it works fine.
<category name="some.package" additivity="false">