Are there any example log4j configuration files (XML).
I have a java main application.
I want log4j to output to console AND write to file.
Any examples of this would be greatly appreciated.
I'm using netbeans if that matters.
Are there any example log4j configuration files (XML).
I have a java main application.
I want log4j to output to console AND write to file.
Any examples of this would be greatly appreciated.
I'm using netbeans if that matters.
The typical thing to do is to put a log4j.properties file in your classpath. The log4j doc will tell you all you need to know about having two appenders for the console and a file, it's in their examples. In other words, don't bother with the less common XML format and stick with the very common properties format.
Just have more than one appender in your log4j.xml, like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss} %5p %c{1} - %m%n"/>
</layout>
</appender>
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false"/>
<param name="file" value="out/learning.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</root>
</log4j:configuration>