当前位置:网站首页>slf4j 简单实现
slf4j 简单实现
2022-07-01 04:19:00 【小道士写程序】
第一:配置文件位置,名称;

第二:配置文件 内容:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="d:/log" />
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<!-- <Encoding>UTF-8</Encoding>-->
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <Encoding>UTF-8</Encoding>-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/myApp.log.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 日志输出级别 -->
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
<!--日志异步到数据库 -->
<!--<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">-->
<!--日志异步到数据库 -->
<!-- <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> -->
<!--连接池 -->
<!-- <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
<user>root</user>
<password>root</password>
</dataSource>
</connectionSource>
</appender>-->
</configuration>
application.yml
server:
port: 8082
logging:
config:
classPath: logback.xml
第三:应用
package com.logtest.demo.action;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class LogAction {
private static final Logger logger = LoggerFactory.getLogger(LogAction.class);
@GetMapping("/hello")
public void hello(){
// logger.trace("trace");
logger.debug("debug");
logger.info("info");
logger.warn("warn");
logger.error("error");
logger.error("我是错误认知");
}
}
边栏推荐
- 使用WinMTR软件简单分析跟踪检测网络路由情况
- 盘点华为云GaussDB(for Redis)六大秒级能力
- 嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
- Use of JMeter counters
- 多次跳槽后,月薪等于老同事的年薪
- 浏览器顶部loading(来自知乎)
- Custom components in applets
- Why is Hong Kong server most suitable for overseas website construction
- Recommend the best product development process in the Internet industry!
- Unexpected token o in JSON at position 1, JSON parsing problem
猜你喜欢

【发送邮件报错】535 Error:authentication failed

不同性能测试工具的并发模式

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

Network metering - application layer

Knowledge supplement: basic usage of redis based on docker

TASK04|數理統計

MallBook:后疫情时代下,酒店企业如何破局?

使用WinMTR软件简单分析跟踪检测网络路由情况

这可能是你进腾讯最后的机会了..

js 图片路径转换base64格式
随机推荐
Learn Chapter 20 of vue3 (keep alive cache component)
What are permissions? What are roles? What are users?
为什么香港服务器最适合海外建站使用
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎
[learn C and fly] S1E20: two dimensional array
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
MFC window scroll bar usage
互联网行业最佳产品开发流程 推荐!
NFT: start NFT royalty journey with eip-2981
283. move zero
LeetCode 1380. Lucky number in matrix
Usage of AfxMessageBox and MessageBox
[untitled]
Embedded System Development Notes 80: using QT designer to design the main interface
Custom components in applets
Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)
Unexpected token o in JSON at position 1, JSON parsing problem
Task04 | statistiques mathématiques
Rule method: number of effective triangles