(A)Log4j 的组成
1.Logger 负责 生成日志
2.Appender 定义输出的地点和文件的属性
3.Layout 定义了输出的格式等
(B)
Log4j有5种级别
FATAL,ERROR,WARN,INFO,DEBUG(从高到低)
(C)
方法有
fatal(Object message)
error(...)
warn(...)
info(...)
debug(...)
log(Priority p, Object message) <参数1级别,2信息>只有大于等于他在文件中定义的级别的信息才会被输出
(D)Appender组件
1.Console(控制台)
2.File(文件)
3.GUI(GUI Component)
4.套接口服务器
5.NT的事件记录器
6.UNIX Syslog守护进程
7.例子
/*************************
log4j.logger.testLogger = WARN,file,console
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File = C:/log.txt
log4j.appender.console = org.apache.log4j.ConsoleAppender
**************************/
8.具体Page258
参考
##LOGGERS##
#configure root logger
log4j.rootLogger = INFO,console #根定义了INFO级别,输出是控制台
#define a logger named helloAppLogger
log4j.logger.helloappLogger=WARN,file #定义了一个helloappLogger继承了rootLogger,级别为WARN,并且因为继承了rootLogger,所以输出为file 和 console(除非把子类的additivity 改为false
#define a second logger that is a child to helloAppLogger
log4j.logger.helloappLogger.childLogger=,file
##APPENDERS##
#define an appender named console ,which is set to be a ConsoleAppender
log4j.appender.console=org.apache.log4j.ConsoleAppender
#define an appender named file, which is set to be a RollingFileAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=c:/logHello.html
#define a simpleLaout to console appender
log4j.appender.file.layout=org.apache.log4j.HTMLLayout
log4j.appender.console.layout=org.apache.log4j.PatternLayout
</script>