spring boot 日志配置详解
作者:大饼油条 时间:2023-09-24 00:23:11
最近在学习spring boot框架的路上,今日看了一下spring boot日志配置,顺便留个笔记记录一下。
1.新建logback.xml文件
内容如下:
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<include resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}/info.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>2</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
</appender>
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<File>${LOG_PATH}/error.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/error-%d{yyyyMMdd}.log.%i
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>2</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
</appender>
<!-- hibernate日志输入 -->
<!-- <logger name="org.hibernate.type.descriptor.sql.BasicBinder"
level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor"
level="TRACE" />
<logger name="org.hibernate.SQL" level="INFO" />
<logger name="org.hibernate.engine.QueryParameters" level="INFO" />
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="INFO" /> -->
<root level="INFO">
<appender-ref ref="INFO_FILE" />
<appender-ref ref="ERROR_FILE" />
</root>
</configuration>
2.然后在application.properties文件中假如如下代码:
#log
logging.config=classpath:logback.xml
logging.path=/workspace/rock/jpa-test/log
3.这时就可以使用log对象了
private final Logger log = Logger.getLogger(this.getClass());
log.info("你好");
注:由于我的项目在d盘,所以第二步设置的文件路径为:d:/workspace/rock/jpa-test/log
运行程序后,进入路径会有三个文件
来源:http://www.cnblogs.com/zb38/p/5411701.html
标签:spring,boot,日志
0
投稿
猜你喜欢
android studio 3.0 service项目背景音乐实现
2023-07-03 23:34:36
SpringBoot打包发布到linux上(centos 7)的步骤
2023-08-11 06:35:55
spring boot打包成可执行jar包
2022-09-26 12:48:14
详解spring cloud ouath2中的资源服务器
2022-09-24 15:36:43
Maven中怎么手动添加jar包到本地仓库详解(repository)
2023-09-08 07:33:20
Maven的几个常用plugin
2021-12-05 13:36:28
Java判断所给年份是平年还是闰年
2023-10-21 17:48:59
WPF中使用CallerMemberName简化InotifyPropertyChanged的实现
2023-05-08 16:27:07
基于Mybatis plus 自动代码生成器的实现代码
2023-11-24 10:40:51
dubbo服务链路跟踪方式
2023-08-24 09:54:21
Java使用DateFormatter格式化日期时间的方法示例
2021-07-15 15:29:23
关于JAVA11中图片与BASE64相互转换的实现
2022-12-06 06:44:11
Android之使用Bundle进行IPC详解
2023-09-27 22:44:56
java状态机方案解决订单状态扭转示例详解
2022-01-10 02:55:43
Spring基于AspectJ的AOP开发案例解析
2021-12-01 01:59:22
举例讲解C语言对归并排序算法的基础使用
2021-05-24 19:48:09
SpringBoot security安全认证登录的实现方法
2021-05-30 08:09:56
解决spring boot启动扫描不到自定义注解的问题
2023-10-29 14:31:48
Springcloud Eureka配置及集群代码实例
2021-09-19 05:54:52
Java 导出excel进行换行的案例
2021-07-29 04:09:36