In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to solve the problem that there is no data in citing Logger.info in slf4j". In daily operation, I believe many people have doubts about how to solve the problem that there is no data in citing Logger.info in slf4j. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to solve the problem that there is no data in Logger.info in citation slf4j". Next, please follow the editor to study!
Slf4j Logger.info prints out only text, no data.
The slf4j package is quoted.
Import org.slf4j.Logger;import org.slf4j.LoggerFactory;private static Logger logger = LoggerFactory.getLogger (TsfTest.class); logger.info ("print parameters:", map)
Can only print out:
2019-06-14 17 52V 07.246 [http-apr-8080-exec-10] INFO c.q.m.p.b.rest.test-print parameters:
Solution
Add curly braces {} to the first parameter.
Logger.info ("print parameters: {}", map)
Solve it!
Enable setting org.slf4j.Logger to print and output logs
Create a new logback.xml under the resouces directory (this is the recommended directory for Logback)
The content is configured as follows
There are two settings for logback:
1. Output to console STDOUT
two。 Export to file FILE
Pom.xml configuration 1.7.25 org.slf4j slf4j-api ${slf4j.version} org.slf4j slf4j-log4j12 1.7.25logback.xml configuration
The following configuration configures both the output to file and the output to the console
% d {yyyy-MM-dd HH:mm:ss.SSS}%-5level [% X {userId}] [% X {requestId}]% logger -% msg%n logFile.log logFile.%d {yyyy-MM-dd_HH-mm} .log.zip% d {HH:mm:ss SSS} [% thread]%-5level% logger {32} -% msg%n program call
1. Declare the logger variable
Private Logger logger = LoggerFactory.getLogger (LoginLogDao.class)
two。 Call the log in the program
Logger.debug (INSERT_LOGIN_LOG_SQL)
Official introduction website: https://logback.qos.ch/demo.html
The following is an introduction to the official website
Logback-classic with two appenders: a ConsoleAppender and a RollingFileAppender. The RollingFileAppender sends logging events to a file called logFile.log and will rollover the active file every minute. The old file will be renamed and compressed to a zip file. The ConsoleAppender will output the logging requests to the console, and shorten the logger names to gain space on the console window, without loss of legibility. For example, ch.qos.logback.demo.prime.NumberCruncherImpl will be abbreviated as c.q.l.d.prime.NumberCruncherImpl.
The output is as follows
IsDebugEnabled true
2017-04-23 23 LoginLogDao.java:32 5815 DEBUG [http-nio-8080-exec-6] (LoginLogDao.java:32)-INSERT INTO t_login_log (user_id,ip,login_datetime) VALUES
2017-04-23 23 JdbcTemplate.java:869 5815 DEBUG [http-nio-8080-exec-6] (JdbcTemplate.java:869)-Executing prepared SQL update
2017-04-23 23 JdbcTemplate.java:616 5815 DEBUG [http-nio-8080-exec-6] (JdbcTemplate.java:616)-Executing prepared SQL statement [INSERT INTO t_login_log (user_id,ip,login_datetime) VALUES (?)]
At this point, the study on "how to solve the problem that there is no data in Logger.info in slf4j" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.