当前位置:网站首页>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>
边栏推荐
- Talk about go language and cloud native technology
- Daily leetcode force deduction (21~25)
- threejs的环境光+点光源+平行光源+球面光 以及hepler理解+阴影()
- Thinkphp6 interface limits user access frequency
- MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)
- Uni app sends request instructions using the escook / request miniprogram plug-in
- Building crud applications in golang
- 优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端
- nifi从入门到实战(保姆级教程)——身份认证
- MySQL high level statements (I)
猜你喜欢
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)
pull request
C/s architecture
Interview shock 60: what will cause MySQL index invalidation?
Operators are also important if you want to learn the C language well
Research Report on the overall scale, major producers, major regions, products and application segments of swine vaccine in the global market in 2022
Raspberry pie 3b+ learning
Usage of rxjs mergemap
How to modify a node_ Files in modules
mysql学习1:安装mysql
随机推荐
私藏干货分享:关于企业架构中如何进行平台化
R语言dplyr包arrange函数排序dataframe数据、通过多个数据列排序dataframe数据、指定第一个字段降序排序,第二字段不指定(默认升序排序)
In 2021, the global enhanced oil production surfactant revenue was about USD 202.3 million, and it is expected to reach USD 297.1 million in 2028
Nifi from introduction to practice (nanny level tutorial) - identity authentication
R language dplyr package arrange function sorts dataframe data, sorts dataframe data through multiple data columns, specifies the first field to be sorted in descending order, and does not specify the
Self taught ADT and OOP
盘点一些好用且小众的 Markdown 编辑器
【On nacos】快速上手 Nacos
千万不要错过,新媒体运营15个宝藏公众号分享
Tidb 6.0: making Tso more efficient tidb Book rush
如何修改 node_modules 里的文件
Interview shock 60: what will cause MySQL index invalidation?
Hands on API development
面试突击60:什么情况会导致 MySQL 索引失效?
Don't miss it. New media operates 15 treasure official account to share
uni-app 使用escook/request-miniprogram插件发请求说明
Interview shock 60: what will cause MySQL index invalidation?
Online bidding of Oracle project management system
树莓派 3b+ 学习
关于枚举类的两种用法