当前位置:网站首页>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("我是错误认知");
}
}
边栏推荐
- TS type gymnastics: illustrating a complex advanced type
- Why is Hong Kong server most suitable for overseas website construction
- Libevent Library Learning
- [TA frost wolf \u may- hundred people plan] 1.2.1 vector basis
- 使用WinMTR软件简单分析跟踪检测网络路由情况
- Unity's 3D multi-point arrow navigation
- Loop filtering based on Unet
- 尺取法:有效三角形的个数
- Redis(七)优化建议
- Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages
猜你喜欢

Threejs opening

Obtain detailed ideas for ABCDEF questions of 2022 American Games

【LeetCode】100. Same tree

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

分账技术赋能农贸市场,重塑交易管理服务效能

Offline installation of Wireshark 2.6.10
![[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle](/img/94/99090ea91082a385968e071ef3766c.png)
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle

NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
![[leetcode skimming] February summary (updating)](/img/62/0d0d9f11434e49d33754a2e4f2ea65.jpg)
[leetcode skimming] February summary (updating)

Unity's 3D multi-point arrow navigation
随机推荐
Why is Hong Kong server most suitable for overseas website construction
283. move zero
Internet winter, how to spend three months to make a comeback
JMeter learning notes 2 - brief introduction to graphical interface
Knowledge supplement: basic usage of redis based on docker
Coinbase in a bear market: losses, layoffs, stock price plunges
206.反转链表
DO280管理应用部署--RC
What is uid? What is auth? What is a verifier?
Concurrent mode of different performance testing tools
Class and object finalization
[human version] Web3 privacy game in the dark forest
为什么香港服务器最适合海外建站使用
Possible problems and solutions of using scroll view to implement slider view
Unity's 3D multi-point arrow navigation
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
做网站数据采集,怎么选择合适的服务器呢?
定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
Do280 management application deployment --rc
js 图片路径转换base64格式