Skip to content

Instantly share code, notes, and snippets.

@timothyshort
Last active March 23, 2018 00:46
Show Gist options
  • Save timothyshort/0632a71c0fee194628624a930b73ff79 to your computer and use it in GitHub Desktop.
Save timothyshort/0632a71c0fee194628624a930b73ff79 to your computer and use it in GitHub Desktop.
Logging with Log4j XML configuration file
<!--
Dependencies:
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<param name="Threshold" value="INFO" />
<!-- FILENAME AND LOCATION -->
<param name="File" value="reports/TestLog.log"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- DEFINE OUTPUT FORMAT -->
<param name="ConversionPattern" value="%d %-5p [%c{1}] %m %n" />
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="fileAppender"/>
</root>
</log4j:configuration>
@timothyshort
Copy link
Author

timothyshort commented Jul 5, 2017

*Place this file in your project root folder.
*This file configures to write a .log file to a sub-folder 'reports' (Line 7), with filename is "TestLog"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment