当前位置:网站首页>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("我是错误认知");
}
}
边栏推荐
- 嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
- Threejs opening
- Web components series (VIII) -- custom component style settings
- 网站服务器:好用的网站服务器怎么选这五方面要关注
- Embedded System Development Notes 79: why should I get the IP address of the local network card
- TASK04|数理统计
- Jenkins自动清理构建历史
- MySQL advanced -- you will have a new understanding of MySQL
- 陈宇(Aqua)-安全-&gt;云安全-&gt;多云安全
- Volley parsing data shows networking failure
猜你喜欢

Hololens2 development environment building and deploying apps

NFT:使用 EIP-2981 開啟 NFT 版稅之旅

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

283.移动零

定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见

Millet College wechat scanning code login process record and bug resolution

Mallbook: how can hotel enterprises break the situation in the post epidemic era?

嵌入式系统开发笔记79:为什么要获取本机网卡IP地址

431. encode n-ary tree as binary tree DFS

NFT: start NFT royalty journey with eip-2981
随机推荐
什么是uid?什么是Auth?什么是验证器?
Concurrent mode of different performance testing tools
Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
Some small knowledge points
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
互联网行业最佳产品开发流程 推荐!
Knowledge supplement: redis' basic data types and corresponding commands
Task04 | statistiques mathématiques
What does ft mean in the data book table
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
ThreeJS开篇
LeetCode 1827. Increment array with minimal operation
【发送邮件报错】535 Error:authentication failed
跳槽一次涨8k,5年跳了3次...
2. Use of classlist (element class name)
All in one 1086: Jiaogu conjecture
浏览器顶部loading(来自知乎)
MallBook:后疫情时代下,酒店企业如何破局?
Haskell lightweight threads overhead and use on multicores
What are permissions? What are roles? What are users?