Log4j
编程技术  /  houtizong 发布于 3年前   156
### 定义根记录器日志级别 ###log4j.rootLogger = debug,stdout,file1,file2### 输出到控制台 ###log4j.appender.stdout = org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target = System.outlog4j.appender.stdout.layout = org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{ 1 }:%L - %m%n### 输出到日志文件 ###log4j.appender.file1 = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.file1.File = logs/log.loglog4j.appender.file1.Append = true### 输出DEBUG级别以上的日志log4j.appender.file1.Threshold = DEBUGlog4j.appender.file1.layout = org.apache.log4j.PatternLayoutlog4j.appender.file1.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n### 保存异常信息到单独文件 ###log4j.appender.file2 = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.file2.File = logs/error.loglog4j.appender.file2.Append = true### 只输出ERROR级别以上的日志log4j.appender.file2.Threshold = ERRORlog4j.appender.file2.layout = org.apache.log4j.PatternLayoutlog4j.appender.file2.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
package test;import org.apache.log4j.Logger;public class Test {private final static Logger logger = Logger.getLogger(Test.class);public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("Test Begin!");logger.debug(" 1. debug ");logger.info(" 2. info ");logger.warn(" 3. warn ");logger.error(" 4. error ");logger.fatal(" 5. fatal ");}}
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" configDebug="true"> <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p] %d [%X{track}] [%X{model}] %m [%t][%c:%L]%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="levelMin" value="DEBUG"/> <param name="AcceptOnMatch" value="true"/> </filter> </appender> <appender name="ERROR" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd-HH"/> <param name="File" value="logs/error.log"/> <param name="Encoding" value="UTF-8"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p] %d [%X{track}] [%X{model}] %m [%t][%c:%L]%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="FATAL"/> <param name="LevelMin" value="ERROR"/> </filter> </appender> <!-- info.log文件只输出info信息 --> <appender name="INFO" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd-HH"/> <param name="File" value="logs/info.log"/> <param name="Encoding" value="UTF-8"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p] %d [%X{track}] [%X{model}] %m [%t][%c:%L]%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="INFO"/> <param name="LevelMin" value="INFO"/> </filter> </appender> <appender name="WARN" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd-HH"/> <param name="File" value="logs/warn.log"/> <param name="Encoding" value="UTF-8"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p] %d [%X{track}] [%X{model}] %m [%t][%c:%L]%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="WARN"/> <param name="LevelMin" value="WARN"/> </filter> </appender> <appender name="DEBUG" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd-HH"/> <param name="File" value="logs/debug.log"/> <param name="Encoding" value="UTF-8"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p] %d [%X{track}] [%X{model}] %m [%t][%c:%L]%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="DEBUG"/> <param name="LevelMin" value="DEBUG"/> </filter> </appender> <root> <priority value="DEBUG"/> <appender-ref ref="DEBUG"/> <appender-ref ref="INFO"/> <appender-ref ref="WARN"/> <appender-ref ref="ERROR"/> <appender-ref ref="CONSOLE"/> </root></log4j:configuration>
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接