当前位置:网站首页>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>
边栏推荐
- Unlock the secret of C language key words (issue 6)
- 面试突击60:什么情况会导致 MySQL 索引失效?
- Self taught ADT and OOP
- Online bidding of Oracle project management system
- R语言dplyr包arrange函数排序dataframe数据、通过多个数据列排序dataframe数据、指定第一个字段降序排序,第二字段不指定(默认升序排序)
- In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
- Daily leetcode force deduction (21~25)
- . Net6 access skywalking link tracking complete process
- 动态规划【三】(区间dp)石子合并
- 56. Core principle of flutter - flutter startup process and rendering pipeline
猜你喜欢

解开C语言的秘密《关键字》(第六期)

1. Mx6ull startup mode

picocli-入门
![Dynamic programming [III] (interval DP) stone merging](/img/a4/82c4d63b8df5d092a96b80dd497147.jpg)
Dynamic programming [III] (interval DP) stone merging

Jwas: a Bayesian based GWAS and GS software developed by Julia

Interview shock 60: what will cause MySQL index invalidation?

如何修改 node_modules 裏的文件

TiDB 6.0:让 TSO 更高效丨TiDB Book Rush

StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior

数学知识——博弈论(巴什博奕、尼姆博奕、威佐夫博奕)思路及例题
随机推荐
uniapp下拉弹层选择框效果demo(整理)
The GLM function of R language is used to build a binary logistic regression model (the family parameter is binomial), and the AIC function is used to compare the AIC values of the two models (simple
Dynamic programming [4] (counting class DP) example: integer partition
R语言使用epiDisplay包的poisgof函数对泊松回归(Poisson Regression)执行拟合优度检验、检验是否存在过度离散问题(overdispersion)
面试突击60:什么情况会导致 MySQL 索引失效?
Private dry goods sharing: how to implement platform in Enterprise Architecture
Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022
How to participate in openharmony code contribution
Time management understood after being urged to work at home
1. Mx6ull startup mode
Raspberry pie 3b+ learning
StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
MapReduce principle analysis (in-depth source code)
threejs的环境光+点光源+平行光源+球面光 以及hepler理解+阴影()
Interview shock 60: what will cause MySQL index invalidation?
Shell script learning notes
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)
How to adjust an integer that is entered in Excel but always displays decimals?
MySQL learning 1: installing MySQL
MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)