I am very new to log4j, so please be careful. But here's what happens, and I donβt know why: it logs the file correctly, but the name of the created log seems incorrect.
Here is my log4j configurator:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%d{HH:mm:ss,SSS}] [%-5p] (%t) [%c{1}] %m%n"/> </layout> </appender> <appender name="file" class="org.apache.log4j.FileAppender"> <param name="File" value="log/messagecount.log" /> <param name="Append" value="true" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%d{HH:mm:ss,SSS}] [%-5p] (%t) [%c{1}] - %m%n"/> </layout> </appender> <root> <level value="debug"/> <appender-ref ref="file"/> </root> </log4j:configuration>
It creates the log4j.log file in the log folder instead of the messagecount.log file. Does this property affect what I think?
This is how I start the recorder:
Class level variable:
private static Logger logger = Logger.getLogger( MessageCount.class );
And the init function:
private void initLogger() throws IOException { Properties props = new Properties(); props.load(getClass().getResourceAsStream("/log4j.xml")); PropertyConfigurator.configure(props); logger.info( "----------Logger init-----------" ) ; // logger.debug("Sample debug message"); // logger.info("Sample info message"); // logger.warn("Sample warn message"); // logger.error("Sample error message"); // logger.fatal("Sample fatal message"); }
The log4j.xml configuration file is in the root of my src folder.
thanks
source share