Home  >  Article  >  Database  >  LogBack学习(1)

LogBack学习(1)

WBOY
WBOYOriginal
2016-06-07 15:32:511566browse

最近在 学习 LogBack相关内容,貌似这东西是Log4j的升级,根据官方说法具体信息参见http://logback.qos.ch/documentation.html,其写文件速度是8或9个微秒,写数据库的时间也在几个毫秒。说是对多线程的日志写入的性能有了大幅度的提升。当前logback有以下几

      最近在学习LogBack相关内容,貌似这东西是Log4j的升级,根据官方说法具体信息参见http://logback.qos.ch/documentation.html,其写文件速度是8或9个微秒,写数据库的时间也在几个毫秒。说是对多线程的日志写入的性能有了大幅度的提升。当前logback有以下几个核心类库:

类库名称

是否必要

logback-access-1.0.13.jar 非必要
logback-classic-1.0.13.jar 必要
logback-core-1.0.13.jar 必要
slf4j-api-1.7.5.jar 必要

从其引入的类库可知它是依赖于slf4j的,而logback-access并非是logback的必备包,只有当你需要特殊的日志记录方式,比如socket、数据库方式等等。。
     通过对其研究,我写了个测试程序由于Logback是非侵入式的,因此这里列出其配置文件:

  

  
    MqClearLog.log
    
      
      MqClearLog-%d{yyyy-MM-dd}.%i.log
      
        
        100MB
      
    
    
      %msg%n
    
  

  
    
  



经测试其输出结果为:

引用


16:22:41,200 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:22:41,200 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:22:41,200 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
16:22:41,201 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration.

16:22:41.247 [main] INFO  chapters.configuration.MyApp2 - Entering application.
16:22:41.249 [main] DEBUG chapters.configuration.Foo - Did it again!
16:22:41.249 [main] INFO  chapters.configuration.MyApp2 - Exiting application.


之后通过阅读官方文档可知去掉”StatusPrinter.print(lc);“此句则不会打印logback的状态,于是我把其去掉了,可之后的输出结果还是和以前的一样,可官方文档上说只要配置文件正确就不会打印可还是有。后经确认为配置问题即

此句为将logback的状态信息打印到console上(一般为屏幕)将此去掉一切就都OK了。烦恼了好久的问题。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn