zoukankan      html  css  js  c++  java
  • 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
    配置文件代码

     

     

     

  • 相关阅读:
    java利用freemarker导出world
    各种Java加密算法
    SM2的非对称加解密java工具类
    Mybatis分页插件--------Pagehelper
    JS实现浏览器打印、打印预览
    java大文件断点续传
    数字证书在web应用中实现登陆
    CA数字加密解密Demo
    使用数字证书进行签名和加密解密
    一个有趣的模拟光照的shader(类似法线贴图)
  • 原文地址:https://www.cnblogs.com/my-program-life/p/11863022.html
Copyright © 2011-2022 走看看