使用日志
第一种定义是 log4j.xml,它把ole和文档质都定义为:
<!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>
<appender name="Daily" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="logs/sample.log" />
<param name="DatePattern" value=" . yyyy-MM-dd-HH-mm" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] - %m%n%n%n" />
</layout>
</appender>
<root>
<appender-ref ref="CA" />
<appender-ref ref="Daily" />
</root>
</log4j:configuration>
将该xml的档案保存在年级。
A sample code is:
4. 一揽子计划:
进口 org.apache.log4j.*;
public class HelloWorld
{
static final Logger logger = Logger.getLogger(HelloWorld.class);
public static void main(String[] args) throws InterruptedException
{
logger.info("I am going to log to file as well as console");
}
}