国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

SpringBoot進(jìn)階教程 | 第二篇:日志組件logback實(shí)現(xiàn)日志分級(jí)打印

yy736044583 / 2130人閱讀

摘要:而的日志文件在由指定。創(chuàng)建啟動(dòng)類控制臺(tái)打印開源項(xiàng)目本地日志打印效果這里因?yàn)榕渲弥袑⒉煌?jí)別的日志設(shè)置了在不同文件中打印,這樣很大程度上方便項(xiàng)目出問題查找問題。

你是否因?yàn)轫?xiàng)目出現(xiàn)問題,查找日志文件定位錯(cuò)誤花費(fèi)N多時(shí)間,是否為此苦不堪言,沒關(guān)系!現(xiàn)在通過這篇文章,將徹底解決你的煩惱,這篇文篇介紹,如何通過logback配置文件將日志進(jìn)行分級(jí)打印,一個(gè)配置文件徹底搞定日志查找得煩惱。

準(zhǔn)備工作

環(huán)境:

windows
jdk 8
maven 3.0
IDEA
構(gòu)建工程


    4.0.0

    
        cn.zhangbox
        spring-boot-study
        1.0-SNAPSHOT
    

    cn.zhangbox
    spring-boot-log
    0.0.1-SNAPSHOT
    jar

    spring-boot-logging
    Demo project for Spring Boot

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


修改YML配置
#選擇哪一個(gè)環(huán)境的配置
#這里可以在每個(gè)環(huán)境配置redis,數(shù)據(jù)庫(mysql),消息(kafka)等相關(guān)的組件的配置
spring:
  profiles:
    active: dev

#文檔塊區(qū)分為三個(gè)---
---
server:
  port: 8081
spring:
  profiles: dev
#日志
logging:
#日志配置文件位置
  config: classpath:log/logback.xml
#日志打印位置,這里是默認(rèn)在項(xiàng)目根路徑下
  path: log/spring-boot-log

#文檔塊區(qū)分為三個(gè)---
---
server:
  port: 8082
spring:
  profiles: test
#日志
logging:
#日志配置文件位置
  config: classpath:log/logback.xml
#日志打印位置,這里是默認(rèn)在項(xiàng)目根路徑下
  path: usr/spring-boot/log/spring-boot-log

#文檔塊區(qū)分為三個(gè)---
---
server:
  port: 8083
spring:
  profiles: prod
#日志
logging:
#日志配置文件位置
  config: classpath:log/logback.xml
#日志打印位置,這里是默認(rèn)在項(xiàng)目根路徑下
  path: usr/spring-boot/log/spring-boot-log
創(chuàng)建日志配置文件

在工程resources文件夾下新建文件夾log,并在該文件夾下創(chuàng)建logback.xml文件,加入以下配置:

     
        
            
            
        
            
            
        
            
            
            
            
            
            
            
        
            
            
                
                    ${CONSOLE_LOG_PATTERN}
                    UTF-8 
                
                
                
                    debug
                
            
        
            
            
                
                ${LOG_PATH}/log_debug.log
                
                
                    %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
                    UTF-8 
                
                
                
                    
                    ${LOG_PATH}/debug/log-debug-%d{yyyy-MM-dd}.%i.log
                    
                    
                        500MB
                    
                    
                    30
                
                
                
                    debug
                    ACCEPT
                    DENY
                
            
        
            
            
                
                ${LOG_PATH}/log_info.log
                
                
                    %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
                    UTF-8 
                
                
                
                    
                    ${LOG_PATH}/info/log-info-%d{yyyy-MM-dd}.%i.log
                    
                    
                        500MB
                    
                    
                    30
                
                
                
                    info
                    ACCEPT
                    DENY
                
            
        
            
            
                
                ${LOG_PATH}/log_warn.log
                
                
                    %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
                    UTF-8 
                
                
                
                    
                    ${LOG_PATH}/warn/log-warn-%d{yyyy-MM-dd}.%i.log
                    
                    
                        500MB
                    
                    
                    30
                
                
                
                    warn
                    ACCEPT
                    DENY
                
            
        
            
            
                
                ${LOG_PATH}/log_error.log
                
                
                    %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
                    UTF-8 
                
                
                
                    
                    ${LOG_PATH}/error/log-error-%d{yyyy-MM-dd}.%i.log
                    
                    
                        500MB
                    
                    
                    30
                
                
                
                    error
                    ACCEPT
                    DENY
                
            
        
            
            
            
        
            
            
                
                    
                    
                    
                    
                    
                
            
        
            
            
                
                    
                    
                    
                    
                
            
        
            
            
                
                    
                    
                    
                    
                
            
        
        

注意loback配置文件中

name的屬性值一定要是當(dāng)前工程的java代碼的完整目錄,因?yàn)?b>mybatis打印的日志級(jí)別是debug級(jí)別的,因此需要配置debug級(jí)別日志掃描的目錄。

創(chuàng)建啟動(dòng)類
    @SpringBootApplication
    public class SpringBootConfigApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(SpringBootConfigApplication.class, args);
        }
    }
控制臺(tái)打印
  .   ____          _            __ _ _
 / / ___"_ __ _ _(_)_ __  __ _    
( ( )\___ | "_ | "_| | "_ / _` |    
 /  ___)| |_)| | | | | || (_| |  ) ) ) )
  "  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2018-07-05 15:05:13.680  INFO 15060 --- [           main] c.z.s.SpringBootLoggingApplication       : Starting SpringBootLoggingApplication on MS-20180428GSYE with PID 15060 (started by Administrator in D:開源項(xiàng)目spring-boot-study)
2018-07-05 15:05:13.685 DEBUG 15060 --- [           main] c.z.s.SpringBootLoggingApplication       : Running with Spring Boot v1.5.3.RELEASE, Spring v4.3.8.RELEASE
2018-07-05 15:05:13.686  INFO 15060 --- [           main] c.z.s.SpringBootLoggingApplication       : The following profiles are active: dev
2018-07-05 15:05:13.766  INFO 15060 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@79d94571: startup date [Thu Jul 05 15:05:13 GMT+08:00 2018]; root of context hierarchy
2018-07-05 15:05:14.223  INFO 15060 --- [kground-preinit] o.h.validator.internal.util.Version      : HV000001: Hibernate Validator 5.3.5.Final
2018-07-05 15:05:15.550  INFO 15060 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
2018-07-05 15:05:15.563  INFO 15060 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2018-07-05 15:05:15.565  INFO 15060 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2018-07-05 15:05:15.703  INFO 15060 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-05 15:05:15.704  INFO 15060 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1938 ms
2018-07-05 15:05:15.869  INFO 15060 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: "dispatcherServlet" to [/]
2018-07-05 15:05:15.876  INFO 15060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "characterEncodingFilter" to: [/*]
2018-07-05 15:05:15.877  INFO 15060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "hiddenHttpMethodFilter" to: [/*]
2018-07-05 15:05:15.877  INFO 15060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "httpPutFormContentFilter" to: [/*]
2018-07-05 15:05:15.877  INFO 15060 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "requestContextFilter" to: [/*]
2018-07-05 15:05:16.219  INFO 15060 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@79d94571: startup date [Thu Jul 05 15:05:13 GMT+08:00 2018]; root of context hierarchy
2018-07-05 15:05:16.298  INFO 15060 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-07-05 15:05:16.299  INFO 15060 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-07-05 15:05:16.328  INFO 15060 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-05 15:05:16.328  INFO 15060 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-05 15:05:16.369  INFO 15060 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-05 15:05:16.616  INFO 15060 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-07-05 15:05:16.636  INFO 15060 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Initializing ProtocolHandler ["http-nio-8081"]
2018-07-05 15:05:16.645  INFO 15060 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Starting ProtocolHandler ["http-nio-8081"]
2018-07-05 15:05:16.659  INFO 15060 --- [           main] o.a.tomcat.util.net.NioSelectorPool      : Using a shared selector for servlet write/read
2018-07-05 15:05:16.679  INFO 15060 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http)
2018-07-05 15:05:16.685  INFO 15060 --- [           main] c.z.s.SpringBootLoggingApplication       : Started SpringBootLoggingApplication in 4.291 seconds (JVM running for 5.767)
本地日志打印效果

這里因?yàn)?b>logback配置中將不同級(jí)別的日志設(shè)置了在不同文件中打印,這樣很大程度上方便項(xiàng)目出問題查找問題。

源碼地址

Spring Boot日志組件logback實(shí)現(xiàn)日志分級(jí)打印源碼

歡迎關(guān)注我的微信公眾號(hào)獲取更多更全的學(xué)習(xí)資源,視頻資料,技術(shù)干貨!

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/71474.html

相關(guān)文章

  • SpringCloud核心教程 | 第三篇:服務(wù)注冊與發(fā)現(xiàn) Eureka篇

    摘要:下一篇介紹基于的服務(wù)注冊與調(diào)用。服務(wù)提供者工程配置這里服務(wù)提供者是使用之前進(jìn)階教程第三篇整合連接池以及監(jiān)控改造而來,這里一樣的部分就不再重復(fù)說明,下面將說明新增的部分。 Spring Cloud簡介 Spring Cloud是一個(gè)基于Spring Boot實(shí)現(xiàn)的云應(yīng)用開發(fā)工具,它為基于JVM的云應(yīng)用開發(fā)中涉及的配置管理、服務(wù)發(fā)現(xiàn)、斷路器、智能路由、微代理、控制總線、全局鎖、決策競選、分...

    scq000 評(píng)論0 收藏0
  • 強(qiáng)推!大牛程序員必備的Java日志框架,性能無敵

    摘要:本文要來分享給大家程序員最常用的日志框架組件。沒有基礎(chǔ)的同學(xué)也不要著急,這套教程覆蓋了目前所有的日志框架,只要你學(xué),就一定用得到,先收藏,以備不時(shí)之需。 作為一名Java程序員,我們開發(fā)了很多Java應(yīng)用程序,包括桌面應(yīng)用、WEB應(yīng)用以及移動(dòng)應(yīng)用。然而日志系統(tǒng)是一個(gè)成熟Java應(yīng)用所必不可少的。在開發(fā)和調(diào)試階段,日志可以幫...

    zebrayoung 評(píng)論0 收藏0
  • springboot超級(jí)詳細(xì)的日志配置(基于logback)

    摘要:默認(rèn)情況下將級(jí)別的日志輸出到控制臺(tái)中,不會(huì)寫到日志文件,且不能進(jìn)行復(fù)雜配置。節(jié)點(diǎn)用于定義變量,方便使用。 showImg(https://raw.githubusercontent.com/FleyX/files/master/blogImg/20190320135049.png); 前言 ??java web 下有好幾種日志框架,比如:logback,log4j,log4j2(slj...

    meislzhua 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<