【视频&交流平台】
http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
https://gitee.com/happyangellxq520/spring-boot
http://412887952-qq-com.iteye.com/blog/2321532
我们之前在其中的一篇文章介绍过如何在spring boot中使用日志记录SLF4J。
Spring Boot在所有内部日志中使用Commons Logging,但是默认配置也提供了对常用日志的支持,如:Java Util Logging,Log4J, Log4J2和Logback。每种Logger都可以通过配置使用控制台或者文件输出日志内容。
这一篇文章我们先从总体介绍下日志的理论知识,在之后的系列中会各个进行介绍如何使用不同的日志框架。
格式化日志
默认的日志输出如下:
2016-06-21 08:23:50.120 INFO 37397 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
输出内容元素具体如下:
时间日期 — 精确到毫秒
日志级别 — ERROR, WARN, INFO, DEBUG or TRACE
进程ID
分隔符 — --- 标识实际日志的开始
线程名 — 方括号括起来(可能会截断控制台输出)
Logger名 — 通常使用源代码的类名
日志内容
控制台输出
在Spring Boot中默认配置了ERROR、WARN和INFO级别的日志输出到控制台。我们可以通过两种方式切换至DEBUG级别:
在运行命令后加入--debug标志,如:$ java -jar myapp.jar --debug
在application.properties中配置debug=true,该属性置为true的时候,核心Logger(包含嵌入式容器、hibernate、spring)会输出更多内容,但是你自己应用的日志并不会输出为DEBUG级别。
多彩输出
如果你的终端支持ANSI,设置彩色输出会让日志更具可读性。通过在application.properties中设置spring.output.ansi.enabled参数来支持。
NEVER:禁用ANSI-colored输出(默认项)
DETECT:会检查终端是否支持ANSI,是的话就采用彩色输出(推荐项)
ALWAYS:总是使用ANSI-colored格式输出,若终端不支持的时候,会有很多干扰信息,不推荐使用
文件输出
Spring Boot默认配置只会输出到控制台,并不会记录到文件中,但是我们通常生产环境使用时都需要以文件方式记录。
若要增加文件输出,需要在application.properties中配置logging.file或logging.path属性。
logging.file,设置文件,可以是绝对路径,也可以是相对路径。如:logging.file=my.log
logging.path,设置目录,会在该目录下创建spring.log文件,并写入日志内容,如:logging.path=/var/log
* 日志文件会在10Mb大小的时候被截断,产生新的日志文件,默认级别为:ERROR、WARN、INFO *
级别控制
在Spring Boot中只需要在application.properties中进行配置完成日志记录的级别控制。
配置格式:logging.level.*=LEVEL
logging.level:日志级别控制前缀,*为包名或Logger名
LEVEL:选项TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
举例:
logging.level.com.didispace=DEBUG:com.didispace包下所有class以DEBUG级别输出
logging.level.root=WARN:root日志以WARN级别输出
自定义日志配置
由于日志服务一般都在ApplicationContext创建前就初始化了,它并不是必须通过Spring的配置文件控制。因此通过系统属性和传统的Spring Boot外部配置文件依然可以很好的支持日志控制和管理。
根据不同的日志系统,你可以按如下规则组织配置文件名,就能被正确加载:
Logback:logback-spring.xml, logback-spring.groovy, logback.xml, logback.groovy
Log4j:log4j-spring.properties, log4j-spring.xml, log4j.properties, log4j.xml
Log4j2:log4j2-spring.xml, log4j2.xml
JDK (Java Util Logging):logging.properties
Spring Boot官方推荐优先使用带有-spring的文件名作为你的日志配置(如使用logback-spring.xml,而不是logback.xml)
自定义输出格式
在Spring Boot中可以通过在application.properties配置如下参数控制输出格式:
logging.pattern.console:定义输出到控制台的样式(不支持JDK Logger)
logging.pattern.file:定义输出到文件的样式(不支持JDK Logger)
【Spring Boot 系列博客】
视频&交流平台:
http://study.163.com/course/introduction.htm?courseId=1004329008
http://412887952-qq-com.iteye.com/blog/2321532
网易云课堂视频最新更新:
第十一章 Spring Boot 日志
1、spring boot日志—理论
2、Spring Boot日志-logback
3、Spring Boot日志-log4j2
第十二章 Spring Boot 知识点2
1、spring boot 服务配置和部署
2、Spring Boot 定制URL匹配规则
历史章节:
第一章 快速开始
1、Spring Boot之Hello World
2、Spring Boot之Hello World访问404
第二章 Spring Boot之JSON
1、spring boot返回json数据
2、Spring Boot完美使用FastJson解析JSON数据
第三章 Spring Boot热部署
1、Spring Boot热部署(springloader)
2、springboot + devtools(热部署)
第四章 Spring Boot数据库
1、Spring Boot JPA/Hibernate/Spring Data概念
2、Spring Boot JPA-Hibernate
3、Spring Boot Spring Data JPA介绍
4、Spring Boot JdbcTemplate
5、Spring Boot集成MyBatis
第五章 web开发
1、全局异常捕捉
2、配置server信息
3、spring boot使用thymeleaf
4、Spring Boot 使用freemarker
5、Spring Boot添加JSP支持
第六章 定时任务
1、Spring Boot定时任务
2、Spring Boot 定时任务升级篇(动态修改cron参数)
3、Spring Boot 定时任务升级篇(动态添加修改删除定时任务)
4、Spring Boot 定时任务升级篇(集群/分布式下的定时任务说明)
5、Spring Boot Quartz介绍
6、Spring Boot Quartz在Java Project中使用
7、Spring Boot 集成Quartz普通使用
8、Spring Boot 集成Quartz升级版
9、Spring Boot 集成Quartz二次升级版
10、Spring Boot 集成Quartz-Job如何自动注入Spring容器托管的对象
第七章 Spring Boot MyBatis升级篇
1、Spring Boot MyBatis升级篇-注解
2、Spring Boot MyBatis升级篇-注解-自增ID
3、Spring Boot MyBatis升级篇-注解-增删改查
4、Spring Boot MyBatis升级篇-注解-分页查询
5、Spring Boot MyBatis升级篇-注解-分页PageHelper不生效
6、Spring Boot MyBatis升级篇-注解- mybatic insert异常:BindingException: Parameter 'name' not found
7、Spring Boot MyBatis升级篇-注解- #和$符号特别篇
8、Spring Boot MyBatis升级篇-注解-@Result
9、Spring Boot MyBatis升级篇-注解-动态SQL(if test)-方案一:<script>
10、Spring Boot MyBatis升级篇-注解-动态SQL(if test)-方案二:@Provider
11、Spring Boot MyBatis升级篇-注解-动态SQL-参数问题
12、Spring Boot MyBatis升级篇-注解-特别篇:@MapperScan和@Mapper
13、Spring Boot MyBatis升级篇-XML
14、Spring Boot MyBatis升级篇-XML-自增ID
15、Spring Boot MyBatis升级篇-XML-增删改查
16、Spring Boot MyBatis升级篇-XML-分页查询
17、Spring Boot MyBatis升级篇-XML-分页PageHelper不生效
18、Spring Boot MyBatis升级篇-XML-动态SQL(if test)
19、Spring Boot MyBatis升级篇-XML-注解-初尝试
20、Spring Boot MyBatis升级篇- pagehelper替换为pagehelper-spring-boot-starter
第八章 Spring Boot 知识点1
1、Spring Boot 拦截器HandlerInterceptor
2、Spring Boot启动加载数据CommandLineRunner
3、Spring Boot环境变量读取和属性对象的绑定
4、Spring Boot使用自定义的properties
5、Spring Boot使用自定义的properties
6、Spring Boot使用@SpringBootApplication
7、Spring Boot 监控和管理生产环境
第十章 Spring Boot 打包部署
1、Spring Boot打包部署((提供Linux的sh文件))
第十一章 Spring Boot 日志
1、spring boot日志—理论
2、Spring Boot日志-logback
3、Spring Boot日志-log4j2
更多查看博客:http://412887952-qq-com.iteye.com/
相关推荐
从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf从零开始学Spring Boot.pdf...
从零开始学Spring Boot,没有积分的可以...(1)spring boot起步之Hello World【从零开始学Spring Boot】: http://412887952-qq-com.iteye.com/blog/2291500 (2)Spring Boot返回json数据【从零开始学Spring Boot】 ...
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2293846
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2292739
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2317365
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2292476
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2299732
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2328358
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2299777
从零开始学Spring Boot。是学习spring Boot的起步资料!!
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2295146
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2305992
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2291500
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2292388
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2301642
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2294952
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2292475