本文主要是介绍6.log4j.properties例子:同时指定多个appender,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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,stdout
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=Message.log
log4j.appender.file.layout=org.apache.log4j.TTCCLayout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.TTCCLayout
控制台:
[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.
文件:
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.
这篇关于6.log4j.properties例子:同时指定多个appender的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!