jquery-bootgrid

http://www.jquery-bootgrid.com/GettingStarted

 

日志是生产环境非常重要的配置,在迁移老的工程到spring-boot时日志的设置兼容很重要,以下是自己在配置日志的时候由于不仔细导致的一些问题备注一下

问题描述

spring boot 默认的日志是console输出,但线上一般都是file输出,所以想修改spring boot的默认输出端

官方文档链接

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html

解决方法

按照官方文档怎么配置都关闭不掉,console和file都会输出,随后又查看了以下两篇文章

http://stackoverflow.com/questions/31935151/prevent-spring-boot-from-printing-logs-to-console
http://stackoverflow.com/questions/26019350/how-to-disable-logback-consoleappender-in-spring-boot/34852737#34852737

没仔细看的话,还是不好使,最后给spring boot 的github发了issue:

https://github.com/spring-projects/spring-boot/issues/5978

查看了作者的回复,有仔细查看了spring-boot有关logback的文档:

https://github.com/spring-projects/spring-boot/tree/master/spring-boot/src/main/resources/org/springframework/boot/logging/logback

结合之前两篇stackoverflow的文章发现spring-boot的1.3.1以后的defaults.xml和base.xml不一样,base.xml里包含了console的appender,所以不能include base.xml,要include defaults.xml.然后自己定义file的appender,最后配置完成logback.xml后ok

注意:

logback.xml或是logback-spring.xml配置文件一定要放到classpath下,默认直接resources的根目录下就可以,但如果你自己特殊的文件夹就需要指定下,比如我自己定义了专门放置配置文件的目录config,那么我首先要在classpath里加入config所在目录,然后指定logback或logback-spring.xml的位置如下:

application.properties

#------------------------
# log
#------------------------
logging.file=account.log
logging.config=classpath:config/logback-spring.xml

总结

    1. spring-boot-1.3.1版本和以后的版本在logback里要include defaults.xml,然后自定义自己的的file-appender
    2. logback.xml一定要放到classpath下
    3. http://coffeesweet.me/2016/08/31/spring-boot%E6%97%A5%E5%BF%97%E9%97%AE%E9%A2%98%E4%B8%80%EF%BC%9A%E5%8E%BB%E9%99%A4%E9%BB%98%E8%AE%A4%E7%9A%84console%E8%BE%93%E5%87%BA/
posted @ 2017-02-11 18:05  沧海一滴  阅读(1367)  评论(0编辑  收藏  举报