日期:2014-05-16  浏览次数:20431 次

log4j指定输出源append、存入数据库并自定义参数

在log4j中可以指定特定的输出源append。在数据库记录日志时,可以将日志文件记录到多个数据库表中。

Java代码 复制代码?
  1. #?This?is?the?configuring?for?logging?displayed?in?the?Application?Server ??
  2. log4j.rootCategory=DEBUG,logfile,stdout ??
  3. ??
  4. log4j.logger.SYSTEM?=?INFO,JDBC ??
  5. log4j.logger.OPERATION?=?INFO,JDBC2 ??
  6. ??
  7. #stdout?configure ??
  8. log4j.appender.stdout=org.apache.log4j.ConsoleAppender ??
  9. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout ??
  10. log4j.appender.stdout.layout.ConversionPattern=?%d?%p?[%c]?-?<%m>%n ??
  11. ??
  12. #logfile?configure ??
  13. log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender ??
  14. log4j.appender.logfile.File=../logs/moca_stm_stm.log ??
  15. log4j.appender.logfile.layout=org.apache.log4j.PatternLayout ??
  16. log4j.appender.logfile.layout.ConversionPattern=?%d{yyyy?MM?dd?HH:mm:ss}?%p?[%c]?-?<%m>%n ??
  17. ??
  18. #JDBC?configure ??
  19. log4j.appender.JDBC.Threshold=INFO ??
  20. log4j.appender.JDBC=org.apache.log4j.jdbc.JDBCAppender? ??
  21. log4j.appender.JDBC.driver=oracle.jdbc.driver.OracleDriver ??
  22. log4j.appender.JDBC.URL=jdbc:oracle:thin:@192.168.140.13:1521:DMPT ??
  23. log4j.appender.JDBC.user=moca_stm ??
  24. log4j.appender.JDBC.password=moca_stm ??
  25. log4j.appender.JDBC.layout=org.apache.log4j.PatternLayout ??
  26. log4j.appender.JDBC.sql=INSERT?INTO?XK_SYS_LOG(USERID,LOGTIME,LOGLEVEL,LOCATION,MESSAGE)VALUES('%X{userId}','%d{yyyy-MM-dd?HH:mm:ss}','%p','%l','%m') ??
  27. ??
  28. ??
  29. log4j.appender.JDBC2.Threshold=INFO ??
  30. log4j.appender.JDBC2=org.apache.log4j.jdbc.JDBCAppender? ??
  31. log4j.appender.JDBC2.driver=oracle.jdbc.driver.OracleDriver ??
  32. log4j.appender.JDBC2.URL=jdbc:oracle:thin:@192.168.140.13:1521:DMPT ??
  33. log4j.appender.JDBC2.user=moca_stm ??
  34. log4j.appender.JDBC2.password=moca_stm ??
  35. log4j.appender.JDBC2.layout=org.apache.log4j.PatternLayout ??
  36. log4j.appender.JDBC2.sql=INSERT?INTO?XK_SYS_LOG_2(USERID,LOGTIME,LOGLEVEL,LOCATION,MESSAGE)VALUES('%X{userId}','%d{yyyy-MM-dd?HH:mm:ss}',