当前位置:网站首页>Idea -- use @slf4j to print logs
Idea -- use @slf4j to print logs
2022-07-26 07:02:00 【MarkerTm】
#pic_center =400x
Series articles :
List of articles
Preface
In previous project development , Log printing is often an indispensable operation .
before
In previous project development , The following methods should be used to print logs , Create a private class instance in each class .
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private Logger log = LoggerFactory.getLogger(Test.class);
Then you need to print the location of the log , Adopt the following methods to display the log :
log.info();
log.warn();
log.debug();
log.error();
But every class needs to actively declare , Is it too much trouble !
Now?
Now you can take @lombok.extern.slf4j.Slf4j Annotation for simplification , The following are the specific implementation steps :
- 1、 Introduce dependency
Because of the use of@Slf4j, This note is alsolombokA note in . Just introduce the following dependencies :
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
</dependency>
- 2、 Add log configuration item
stayresourcesAdd in folderlog4j.propertiesThe configuration file , The configuration information is shown below
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=firestorm.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.logger.com.codefutures=DEBUG
- 3、 Use... In classes
@Slf4j
The effect after execution is as follows :
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Test {
public static void main(String[] args) {
log.info(" Focus on writing bug");
}
}

IDEA When compiling, report Error: java: Symbol not found : Variable log lombok Failure problem
IDEA When compiling, report Error: java: Symbol not found : Variable log lombok Failure problem
边栏推荐
- Log rotation logrotate
- C # use log4net plug-in to output logs to files
- 数据库性能测试(mysql)
- Question: can't download sh shellcheck Please install it manually and some commands of shell script
- Drools(2):Drools快速入门
- 优炫数据库JDBC打开日志方式有哪些
- buuReserve(4)
- Solve the problem that Chrome browser is tampered with by drug bullies
- [hardware ten treasures] - 7.1 [dynamic RAM] key points of DDR hardware design
- Vim中删除^M
猜你喜欢

Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !

vulnhub Lampião: 1

Queue assistant | product update log in June 2022

XSS labs (1-10) break through details

【无标题】转载

怎样在win10家庭版中使用Hyper-V

Question: can't download sh shellcheck Please install it manually and some commands of shell script

MySQL Foundation (II) -- MySQL Foundation

【硬十宝典】——7.2【动态RAM】DDR4与DDR3区别解析

Binary tree knowledge summary
随机推荐
10 papers of ant security laboratory were included by ccf-a top meeting to explore the realization of AI credibility from the perspective of algorithm
buuReserve(4)
123123123
buuReserve(4)
The creation of "harmonyos" project and the use of virtual machines
LTS(Light-Task-Scheduler)
Delete ^m from VIM
Acwing- daily question
Solve the problem that Chrome browser is tampered with by drug bullies
IDEA——使用@Slf4j打印日志
敏捷整洁之道
On the difference between Eval and assert
Kubernetes scheduling concept and workflow
< II> ObjectARX development: create and edit basic graphic objects
String and memory functions
Drools(4):Drools基础语法(2)
Benefits of the builder model
Shared lock
QT监听socket事件,使用QSocketNotifier类
Click "Niuke | daily question" to eliminate it