当前位置:网站首页>Detailed configuration of log4j
Detailed configuration of log4j
2022-06-27 12:19:00 【Jinlin】
Loggers (Logger) Their behavior is hierarchical . It is divided into
- OFF
- FATAL
- WARN
- INFO
- DEBUG
- TRACE
- ALL
Log4j It is recommended to use only four levels , The priorities from high to low are ERROR、WARN、INFO、DEBUG. By the level defined here , You can control the switch to the corresponding level of log information in the application .
For example, it defines INFO Level , Then all of the DEBUG Level log information will not be printed out .
The program will print logs higher than or equal to the set level , The higher the log level is set , The less logs you print out .
If you set the level to INFO, The priority is higher than or equal to INFO Level ( Such as :INFO、WARN、
ERROR) The log information of will be output , Less than this level DEBUG Will not be output .
log4j.properties File configuration
Code block
log4j.rootLogger = debug , syso , D
### Output to console ###
log4j.appender.syso = org.apache.log4j.ConsoleAppender
log4j.appender.syso.Target = System.out
log4j.appender.syso.Threshold = debug ## Output DEBUG Log above level
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
### Output to a log file ###
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 ## Output DEBUG Log above level
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
### Save exception information to a separate file ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = D:/logs/errorSalary.log ## Exception log file name
log4j.appender.D.Append = true
log4j.appender.D.Threshold = ERROR ## Output DEBUG Log above level
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 To configure
/**
* Log Support for Need to call log4j Configured classes
*/
protected Log log = LoggerUtil.newLogger(getClass());
public final class LoggerUtil {
/**
* initialization Logger class
*/
@SuppressWarnings("unchecked")
public static final Log newLogger(Class className) {
Logger logger = Logger.getLogger(className);
Log4JLogger log = new Log4JLogger(logger);
return log;
}
}
// test class
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 The dependent jar package
<!-- 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>
边栏推荐
- threejs的环境光+点光源+平行光源+球面光 以及hepler理解+阴影()
- 居家办公被催之后才明白的时间管理
- 动态规划【三】(区间dp)石子合并
- C # WPF realizes undo redo function
- 秒云荣获《2022爱分析 · IT运维厂商全景报告》智能运维AIOps市场代表厂商
- StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
- Raspberry pie 3b+ learning
- alibaba jarslink
- Don't miss it. New media operates 15 treasure official account to share
- 聊聊 Go 语言与云原生技术
猜你喜欢

dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article

数学知识——博弈论(巴什博奕、尼姆博奕、威佐夫博奕)思路及例题

alibaba jarslink

私藏干货分享:关于企业架构中如何进行平台化

$15.8 billion! 2021 the world's top15 most profitable hedge fund giant

怎么找相同台词的影视片段?这8个电影搜索神器,一句台词找到对应片段

MapReduce实战小案例(自定义排序、二次排序、分组、分区)

Youboxun attended the openharmony technology day to create a new generation of secure payment terminals

号称史上最难618,淘宝数据盘点你做对了吗?

pull request
随机推荐
Dynamic programming [4] (counting class DP) example: integer partition
MapReduce实战小案例(自定义排序、二次排序、分组、分区)
Drive to APasS! Use Mingdao cloud to manage F1 events
手把手带你入门 API 开发
This privatized deployed enterprise knowledge base makes telecommuting a zero distance
Topic38——56. Consolidation interval
行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
Rxjs mergeMap 的使用场合
How to adjust an integer that is entered in Excel but always displays decimals?
R语言glm函数构建二分类logistic回归模型(family参数为binomial)、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
.NET6接入Skywalking链路追踪完整流程
1. Mx6ull startup mode
最短编辑距离(线性dp写法)
Unlock the secret of C language key words (issue 6)
Building crud applications in golang
C # WPF realizes undo redo function
Topic37——64. Minimum path sum
picocli-入门
Jwas: a Bayesian based GWAS and GS software developed by Julia
mysql学习1:安装mysql