博客
关于我
Springboot2模块系列:日志slf4j2(持久化)
阅读量:244 次
发布时间:2019-03-01

本文共 2146 字,大约阅读时间需要 7 分钟。

排除Spring Boot默认日志框架,使用SLF4J2进行日志持久化配置

1. 排除Spring Boot默认日志框架,引入SLF4J2

在Spring Boot项目中,默认使用spring-boot-starter-logging进行日志处理。为了使用更灵活的日志框架SLF4J2,我们需要在依赖管理中排除Spring Boot的日志相关组件。具体配置如下:

org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-log4j2

2. SLF4J2日志配置文件

为了实现日志的持久化存储,我们需要配置SLF4J2日志框架。以下是一个典型的slf4j2.xml配置示例:

ddd
logs/${app_name}

3. 应用配置文件

在application.yml中引入日志配置文件:

logging:    level:        root: info    config:        classpath: config/slf4j2.xml

4. 使用方法

使用SLF4J作为日志输出工具,例如:

import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class LoggerSave {    static Logger logger = LoggerFactory.getLogger(LoggerSave.class);    public void main(String[] args) {        logger.error("error test");    }}

通过以上配置,您可以实现日志的持久化存储和管理,同时灵活控制日志级别和输出格式。

转载地址:http://hvht.baihongyu.com/

你可能感兴趣的文章
python中函数接受参数为*args, **kwargs怎么办
查看>>
Python中切片的高效迭代
查看>>
python中列表乘法、eval、lambda、hasattr、assert、*(星)等的用法
查看>>
Python中制作词云的WordCloud参数详解
查看>>
Python中可用和使用的系统内存?
查看>>
python中存根文件(.pyi)的用途是什么?
查看>>
Python中实现ASCII码与字符相互转换
查看>>
Python中实现获取所有微信好友的头像并拼接成一张图片
查看>>
Python中对象的布尔值
查看>>
python中对集合的操作
查看>>
python中将列表转换为元组的时间复杂度,反之亦然
查看>>
Python中布尔表达式的求值
查看>>
python中很常用的10个内置函数整理(初学必备)
查看>>
python中打印二维列表数据
查看>>
python中打散数组shuffle
查看>>
Python中执行外部命令
查看>>
Python中拼接numpy数组-ChatGPT4o作答
查看>>
Python中提示:no module named 'PIL'
查看>>
Python中提示:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position
查看>>
python中数据类型存储_浅谈Python中的数据类型
查看>>