• Log4j入门教程


    在maven仓库搜索log4j配置  https://mvnrepository.com/tags/maven

     1 log4j.rootLogger=DEBUG, Console ,File
     2 
     3 #Console
     4 log4j.appender.Console=org.apache.log4j.ConsoleAppender  
     5 log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
     6 log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
     7 #File
     8 log4j.appender.File = org.apache.log4j.FileAppender
     9 log4j.appender.File.File = F://log.log
    10 log4j.appender.File.layout = org.apache.log4j.PatternLayout
    11 log4j.appender.File.layout.ConversionPattern =%d [%t] %-5p [%c] - %m%n
    配置文件

     

     1 package com.uos.log4j;
     2 
     3 import org.apache.log4j.Logger;
     4 
     5 
     6 public class Log4jTest {
     7 
     8     private static Logger logger = Logger.getLogger(Log4jTest.class);
     9     public static void main(String[] args) {
    10         logger.fatal("严重错误fatal信息");
    11         logger.error("报错error信息");
    12         logger.warn("警告warn信息");
    13         logger.debug("调试debug信息");
    14         logger.info("普通info信息");
    15         logger.error("报错信息", new IllegalArgumentException("非法参数"));
    16     }
    17 }
    测试代码

     

     

     1 log4j.rootLogger=DEBUG, Console ,File,DailyRollingFile,RollingFile
     2 
     3 #Console
     4 log4j.appender.Console=org.apache.log4j.ConsoleAppender  
     5 log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
     6 log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
     7 #File
     8 log4j.appender.File = org.apache.log4j.FileAppender
     9 log4j.appender.File.File = F://log2.log
    10 log4j.appender.File.layout = org.apache.log4j.PatternLayout
    11 log4j.appender.File.layout.ConversionPattern =%d [%t] %-5p [%c] - %m%n
    12 
    13 
    14 #DailyRollingFile
    15 log4j.appender.DailyRollingFile = org.apache.log4j.DailyRollingFileAppender
    16 log4j.appender.DailyRollingFile.File = F://log3.log
    17 log4j.appender.DailyRollingFile.layout = org.apache.log4j.PatternLayout
    18 log4j.appender.DailyRollingFile.layout.ConversionPattern =%d [%t] %-5p [%c] - %m%n
    19 
    20 #RollingFile
    21 log4j.appender.RollingFile = org.apache.log4j.RollingFileAppender
    22 log4j.appender.RollingFile.File = F://log4.log
    23 log4j.appender.RollingFile.MaxFileSize=1KB
    24 log4j.appender.RollingFile.MaxBackupIndex=3
    25 log4j.appender.RollingFile.layout = org.apache.log4j.PatternLayout
    26 log4j.appender.RollingFile.layout.ConversionPattern =%d [%t] %-5p [%c] - %m%n
    配置文件代码

     

     

     

  • 相关阅读:
    HDU 1394 Minimum Inversion Number
    HDU 4931 Happy Three Friends
    BZOJ 1089 严格n元树 (递推+高精度)
    BZOJ 1088 扫雷Mine (递推)
    BZOJ 3038 上帝造题的七分钟2 (并查集+树状数组)
    BZOJ 3211 花神游历各国 (树状数组+并查集)
    BZOJ 1087 互不侵犯King (位运算)
    BZOJ 1002 轮状病毒 (基尔霍夫矩阵)
    BZOJ 1005 明明的烦恼 (组合数学)
    BZOJ 1058 报表统计 (STL)
  • 原文地址:https://www.cnblogs.com/my-program-life/p/11863022.html
Copyright © 2020-2023  润新知