Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How springboot writes to multiple log files at different levels

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Springboot how to write multiple log files at different levels, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Create a logback-spring.xml in the resource directory with the following file content

Logback debug ${CONSOLE_LOG_PATTERN} UTF-8 ${log.path} / ${log.name} _ info.log % d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n UTF-8 ${log.path} / ${log.name}-info-%d {yyyy-MM-dd}.% i.log 100MB 60 info ACCEPT DENY ${log.path} / ${log.name} _ error.log% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level % logger {50} -% msg%n UTF-8 ${log.path} / ${log.name}-error-%d {yyyy-MM-dd}.% i.log 100MB 60 ERROR ACCEPT DENY

Add the following to the yml file in the resource directory

Logging: config: classpath:logback-spring.xml / / location can be specified

Write to the log content

@ Servicepublic class CreateCodeService {private static final Logger logger = LoggerFactory.getLogger (CreateCodeService.class); public CreateCodeDto createCodeFunc (CreateCodeBean createCodeBean) {try {} catch (EncodeBase64Exception e) {logger.error (TimeUtils.getCurrentTime () + "EncodeBase64 exception"); return createCodeDto;} catch (Exception e) {logger.error (TimeUtils.getCurrentTime () + "unknown exception") Return createCodeDto;}

Close the console to print the log

Logging: level: com: error # close the console to print the following log output com to the directory org: springframework: web: errorserver: port: 8083 # cassandra database connection under java. Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report