Config log4j in standalone app

1. First make sure you've added the log4j.jar

2. config log4j.xml and log4j.properties

Show an example:

log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
	<appender name="CA" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
		</layout>
	</appender>
	<root>
		<level value="debug" />
		<appender-ref ref="CA" />
	</root>
</log4j:configuration>

log4j.properties

log4j.rootLogger=DEBUG, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Done!

http://www.dzone.com/tutorials/java/log4j/log4j-xml-configuration.html

你可能感兴趣的:(log4j,log4j,APP,configuration,configuration,standalone)