当前位置:网站首页>log4j的详情配置
log4j的详情配置
2022-06-27 11:55:00 【瑾琳】
日志记录器(Logger)的行为是分等级的。分为
- OFF
- FATAL
- WARN
- INFO
- DEBUG
- TRACE
- ALL
Log4j建议只使用四个级别,优先级从高到低分别是ERROR、WARN、INFO、DEBUG。通过在这里定义的级别,您可以控制到应用程序中相应级别的日志信息的开关。
比如在这里定义了INFO级别,则应用程序中所有DEBUG级别的日志信息将不被打印出来。
程序会打印高于或等于所设置级别的日志,设置的日志等级越高,打印出来的日志就越少。
如果设置级别为INFO,则优先级高于等于INFO级别(如:INFO、WARN、
ERROR)的日志信息将可以被输出,小于该级别的如DEBUG将不会被输出。
log4j.properties文件配置
代码块
log4j.rootLogger = debug , syso , D
### 输出到控制台 ###
log4j.appender.syso = org.apache.log4j.ConsoleAppender
log4j.appender.syso.Target = System.out
log4j.appender.syso.Threshold = debug ## 输出DEBUG级别以上的日志
log4j.appender.syso.layout = org.apache.log4j.PatternLayout
log4j.appender.syso.layout.ConversionPattern = %d{[yyyy/MM/dd HH:mm:ss,SSS]} [%5p] [%c:%L] - %m%n
### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = D:/logs/Salary.log
log4j.appender.D.Append = true
### \u8F93\u51FADEBUG\u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7
log4j.appender.D.Threshold = DEBUG ## 输出DEBUG级别以上的日志
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %d{[yyyy/MM/dd HH:mm:ss,SSS]} [%5p] [%c:%L] - %m%n
### 保存异常信息到单独文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = D:/logs/errorSalary.log ## 异常日志文件名
log4j.appender.D.Append = true
log4j.appender.D.Threshold = ERROR ## 输出DEBUG级别以上的日志
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %d{[yyyy/MM/dd HH:mm:ss,SSS]} [%5p] [%c:%L] - %m%n
java配置
/**
* Log的支持 需要调用log4j配置的类
*/
protected Log log = LoggerUtil.newLogger(getClass());
public final class LoggerUtil {
/**
* 初始化Logger 类
*/
@SuppressWarnings("unchecked")
public static final Log newLogger(Class className) {
Logger logger = Logger.getLogger(className);
Log4JLogger log = new Log4JLogger(logger);
return log;
}
}
//测试 类
public class TestLog4j {
public static void main(String[] args) {
PropertyConfigurator.configure( " D:/Code/conf/log4j.properties " );
Logger logger = Logger.getLogger(TestLog4j. class );
logger.debug( " debug " );
logger.error( " error " );
}
pom所依赖的jar包
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.8.0-beta2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
边栏推荐
- StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
- hibernate操作oracle数据库 主键自增
- c/s 架构
- mysql学习1:安装mysql
- The R language uses the follow up The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The labels parameter adds label information t
- master公式
- "24 of the 29 students in the class successfully went to graduate school" rushed to the hot search! Where are the remaining five?
- 57. The core principle of flutter - layout process
- 如何修改 node_modules 里的文件
- 一个有趣的网络掩码的实验
猜你喜欢

Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022

MySQL high level statements (I)

Interview shock 60: what will cause MySQL index invalidation?

"24 of the 29 students in the class successfully went to graduate school" rushed to the hot search! Where are the remaining five?

优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端

面试突击60:什么情况会导致 MySQL 索引失效?

剑指 Offer 04. 二维数组中的查找

mysql学习1:安装mysql

On ticheck

Interviewer: with the for loop, why do you need foreach?
随机推荐
The R language uses the follow up The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The labels parameter adds label information t
今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
Neo4j:入门基础(一)之安装与使用
内存四区(栈,堆,全局,代码区)
【On nacos】快速上手 Nacos
alibaba jarslink
Hands on API development
build.gradle 配置
巅峰小店APP仿站开发玩法模式讲解源码分享
Jianmu continuous integration platform v2.5.0 release
关于枚举类的两种用法
Daily leetcode force deduction (21~25)
Private dry goods sharing: how to implement platform in Enterprise Architecture
Wechat applet realizes five-star evaluation
Thinkphp6 interface limits user access frequency
建木持续集成平台v2.5.0发布
$15.8 billion! 2021 the world's top15 most profitable hedge fund giant
Deep understanding of happens before principle
Interviewer: with the for loop, why do you need foreach?
MySQL高阶语句(一)