Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How springboot writes to multiple log files at different levels

Shulou Source: shulou.com Published: 2022-06-01 18:38:15 09月30日 Update

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.

Tags: Log level content directory file attribute statement UTF-8 configuration superior character set console help control multiple clear code representative location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info MariaDB Linux OPPO Reno