package com.v512.log4j;
import org.apache.log4j.Logger;
public class HelloLog4J {
// 构造记录器,形参是记录器所在的类,表示要在该类做日志
private static Logger logger = Logger.getLogger(HelloLog4J.class);
/**
* @param args
*/
public static void main(String[] args) {
getMessage();
}
private static void getMessage() {
// 记录下各种级别的信息,这些信息放在哪儿,以哪种方式存放,在log4j.properties文件中配置.
logger.debug("This is debug message.");
logger.info("This is a info message.");
logger.warn("This is a warn message.");
logger.error("This is a error message.");
}
}
log4j.rootLogger=info,file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=Message.log
log4j.appender.file.layout=org.apache.log4j.TTCCLayout
Message.log(工程目录下)
[main] INFO com.v512.log4j.HelloLog4J - This is a info message.
[main] WARN com.v512.log4j.HelloLog4J - This is a warn message.
[main] ERROR com.v512.log4j.HelloLog4J - This is a error message.