logback 日志级别不可控问题解决
来源:互联网 发布:网络几分钟断一次 编辑:程序博客网 时间:2024/06/06 13:57
1、问题
在使用slf4j+log4j时,发现输出的日志总是在DEBUG级别,而且格式非logback.xml中给出的格式。
logback.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?><configuration><!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 --><property name="LOG_HOME" value="d:/logs" /><appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"><encoder><pattern>HERE %d{HH:mm:ss.SSS} [%thread] %-5level %C{36} %L - %msg%n</pattern> </encoder></appender><Encoding>UTF-8</Encoding><!-- 日志输出级别 --><root level="info"><appender-ref ref="stdout" /> </root></configuration>
输出结果(部分截取):
信息: Initializing Spring root WebApplicationContext14:20:53.084 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started14:20:53.136 [localhost-startStop-1] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Found Equinox FileLocator for OSGi bundle URL resolution14:20:53.206 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence14:20:53.206 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence14:20:53.212 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [jndiProperties] PropertySource with lowest search precedence14:20:53.213 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence14:20:53.217 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence14:20:53.217 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]14:20:53.227 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]14:20:53.228 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri Jul 29 14:20:53 CST 2016]; root of context hierarchy14:20:53.300 [localhost-startStop-1] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence14:20:53.300 [localhost-startStop-1] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence14:20:53.301 [localhost-startStop-1] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]14:20:53.317 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatch-servlet.xml]14:20:53.320 [localhost-startStop-1] DEBUG org.springframework.beans.factory.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]14:20:53.354 [localhost-startStop-1] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]14:20:53.360 [localhost-startStop-1] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver - Loaded schema mappings: {http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/aop/spring-aop-4.1.xsd=org/springframework/aop/config/spring-aop-4.1.xsd, http://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd=org/springframework/jdbc/config/spring-jdbc-4.1.xsd, http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd=org/springframework/web/servlet/config/spring-mvc-4.1.xsd, http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, http://www.springframework.org/schema/security/spring-security-3.0.3.xsd=org/springframework/security/config/spring-security-3.0.3.xsd, http://www.springframework.org/schema/security/spring-security-2.0.1.xsd=org/springframework/security/config/spring-security-2.0.1.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-4.1.xsd, http://www.springframework.org/schema/aop/spring-aop-3.2.xsd=org/springframework/aop/config/spring-aop-3.2.xsd, http://www.springframework.org/schema/lang/spring-lang-4.1.xsd=org/springframework/scripting/config/spring-lang-4.1.xsd, http://www.springframework.org/schema/context/spring-context-4.0.xsd=org/springframework/context/config/spring-context-4.0.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd=org/springframework/web/servlet/config/spring-mvc-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-4.1.xsd=org/springframework/beans/factory/xml/spring-tool-4.1.xsd, http://www.springframework.org/schema/lang/spring-lang-3.2.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/cache/spring-cache-3.2.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-4.1.xsd=org/springframework/ejb/config/spring-jee-4.1.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd=org/springframework/jdbc/config/spring-jdbc-3.1.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-4.1.xsd, http://www.springframework.org/schema/cache/spring-cache-4.1.xsd=org/springframework/cache/config/spring-cache-4.1.xsd, http://www.springframework.org/schema/aop/spring-aop-4.0.xsd=org/springframework/aop/config/spring-aop-4.0.xsd, http://www.springframework.org/schema/security/spring-security-2.0.xsd=org/springframework/security/config/spring-security-2.0.xsd, http://www.springframework.org/schema/jee/spring-jee-3.2.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd=org/springframework/jdbc/config/spring-jdbc-4.0.xsd, http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd=org/springframework/web/servlet/config/spring-mvc-4.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-4.0.xsd=org/springframework/scripting/config/spring-lang-4.0.xsd, http://www.springframework.org/schema/mvc/spring-mvc.xsd=org/springframework/web/servlet/config/spring-mvc-4.1.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd=org/springframework/web/servlet/config/spring-mvc-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-4.1.xsd=org/springframework/beans/factory/xml/spring-beans-4.1.xsd, http://www.springframework.org/schema/tool/spring-tool-4.0.xsd=org/springframework/beans/factory/xml/spring-tool-4.0.xsd, http://www.springframework.org/schema/tx/spring-tx-3.2.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://www.springframework.org/schema/lang/spring-lang-3.1.xsd=org/springframework/scripting/config/spring-lang-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache-3.1.xsd=org/springframework/cache/config/spring-cache-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-4.0.xsd=org/springframework/ejb/config/spring-jee-4.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd, http://www.springframework.org/schema/task/spring-task-4.1.xsd=org/springframework/scheduling/config/spring-task-4.1.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc.xsd=org/springframework/jdbc/config/spring-jdbc-4.1.xsd, http://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-4.1.xsd=org/springframework/transaction/config/spring-tx-4.1.xsd, http://www.springframework.org/schema/cache/spring-cache-4.0.xsd=org/springframework/cache/config/spring-cache-4.0.xsd, http://www.springframework.org/schema/jee/spring-jee-3.1.xsd=org/springframework/ejb/config/spring-jee-3.1.xsd, http://www.springframework.org/schema/task/spring-task-3.2.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-4.1.xsd, http://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd=org/springframework/web/servlet/config/spring-mvc-3.0.xsd, http://www.springframework.org/schema/beans/spring-beans-4.0.xsd=org/springframework/beans/factory/xml/spring-beans-4.0.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-4.1.xsd, http://www.springframework.org/schema/security/spring-security-2.0.4.xsd=org/springframework/security/config/spring-security-2.0.4.xsd, http://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-3.0.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/task/spring-task-4.0.xsd=org/springframework/scheduling/config/spring-task-4.0.xsd, http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx-4.0.xsd=org/springframework/transaction/config/spring-tx-4.0.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/security/spring-security-3.2.xsd=org/springframework/security/config/spring-security-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-3.0.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/util/spring-util-4.1.xsd=org/springframework/beans/factory/xml/spring-util-4.1.xsd, http://www.springframework.org/schema/task/spring-task-3.1.xsd=org/springframework/scheduling/config/spring-task-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-4.1.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.springframework.org/schema/task/spring-task.xsd=org/springframework/scheduling/config/spring-task-4.1.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/security/spring-security-3.1.xsd=org/springframework/security/config/spring-security-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/util/spring-util-4.0.xsd=org/springframework/beans/factory/xml/spring-util-4.0.xsd, http://www.springframework.org/schema/task/spring-task-3.0.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-4.1.xsd, http://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/cache/spring-cache.xsd=org/springframework/cache/config/spring-cache-4.1.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-4.1.xsd, http://www.springframework.org/schema/security/spring-security-2.0.2.xsd=org/springframework/security/config/spring-security-2.0.2.xsd, http://www.springframework.org/schema/context/spring-context-4.1.xsd=org/springframework/context/config/spring-context-4.1.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-3.2.xsd, http://www.alibaba.com/schema/stat.xsd=META-INF/stat.xsd, http://www.springframework.org/schema/security/spring-security-3.0.xsd=org/springframework/security/config/spring-security-3.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-4.1.xsd}1
从日志输出结果可以看到:即便在logback.xml配置文件中设置了输入级别为info,却仍然有DEBUG级别的日志输出,而且,日志应以“HERE”前缀开头,因为输出格式中有配置:
<pattern>HERE %d{HH:mm:ss.SSS} [%thread] %-5level %C{36} %L - %msg%n</pattern>但结果却没有HERE字样的日志输出,这说明logback.xml并未生效,系统使用的是其他的配置文件或缺省的配置(缺省配置级别为DEBUG)。
2、分析
通过反复的测试,发现竟然是类的加载先后顺序问题。在web.xml中配置了logback.xml加载的文件即加载方式(监听器),见下面的文件:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false" version="3.0"> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>webAppRootKey</param-name> <param-value>Workflow</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatch-servlet.xml,/WEB-INF/conf/spring/*.xml,classpath*:META-INF/conf/spring/*.xml</param-value> </context-param> <context-param> <param-name>logbackConfigLocation</param-name> <param-value>/WEB-INF/conf/logback.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class> </listener> <servlet> <servlet-name>dispatch</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatch</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping></web-app>
spring 启动的监听器(org.springframework.web.context.ContextLoaderListener) 在logback日志配置监听器(ch.qos.logback.ext.spring.web.LogbackConfigListener)之前加载,这时日志配置尚未加载,SPRING容器已启动,采用缺省的logback配置,随后即便logback日志加载成功,logback级别已经为DEBUG,且不能再改回来。
3、解决办法
解决的办法竟然很简单,那就是将spring 启动的监听器(org.springframework.web.context.ContextLoaderListener)和logback日志配置监听器(ch.qos.logback.ext.spring.web.LogbackConfigListener)掉过个,正确的配置顺序为:
(1)ch.qos.logback.ext.spring.web.LogbackConfigListener
(2)org.springframework.web.context.ContextLoaderListener
修改后的web.xml为:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false" version="3.0"> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>webAppRootKey</param-name> <param-value>Workflow</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatch-servlet.xml,/WEB-INF/conf/spring/*.xml,classpath*:META-INF/conf/spring/*.xml</param-value> </context-param> <context-param> <param-name>logbackConfigLocation</param-name> <param-value>/WEB-INF/conf/logback.xml</param-value> </context-param> <listener> <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatch</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatch</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping></web-app>
正常输出样例:
HERE 14:48:33.510 [localhost-startStop-1] INFO o.s.web.context.ContextLoader 285 - Root WebApplicationContext: initialization startedHERE 14:48:33.643 [localhost-startStop-1] INFO o.s.c.s.AbstractApplicationContext 510 - Refreshing Root WebApplicationContext: startup date [Fri Jul 29 14:48:33 CST 2016]; root of context hierarchyHERE 14:48:33.720 [localhost-startStop-1] INFO o.s.b.f.xml.XmlBeanDefinitionReader 317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatch-servlet.xml]HERE 14:48:36.290 [localhost-startStop-1] INFO o.s.b.f.xml.XmlBeanDefinitionReader 317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/conf/spring/px-hessian-client.xml]HERE 14:48:36.327 [localhost-startStop-1] INFO o.s.b.f.xml.XmlBeanDefinitionReader 317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/conf/spring/px-common.xml]HERE 14:48:37.545 [localhost-startStop-1] INFO o.s.b.f.s.DefaultListableBeanFactory 822 - Overriding bean definition for bean 'beanFactory': replacing [Generic bean: class [com.nariit.pi6000.framework.platform.PXBeanFactory]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/dispatch-servlet.xml]] with [Generic bean: class [com.nariit.pi6000.framework.platform.PXBeanFactory]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/conf/spring/px-common.xml]]HERE 14:48:37.548 [localhost-startStop-1] INFO o.s.b.f.xml.XmlBeanDefinitionReader 317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/conf/spring/px-ds.xml]HERE 14:48:37.599 [localhost-startStop-1] INFO o.s.b.f.xml.XmlBeanDefinitionReader 317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/conf/spring/px-bpm.xml]HERE 14:48:37.972 [localhost-startStop-1] INFO o.s.c.i.s.PropertiesLoaderSupport 172 - Loading properties file from ServletContext resource [/WEB-INF/conf/jdbc.properties]HERE 14:48:37.973 [localhost-startStop-1] INFO o.s.c.i.s.PropertiesLoaderSupport 172 - Loading properties file from ServletContext resource [/WEB-INF/conf/props/platform.properties]
正常输出没有DEBUG级别的日志输出,而且输出日志中带有“HERE ”前缀,与预设logback.xml配置一致。
4、注意事项
slf4j+logback需要用到的包:
slf4j1个包:
(1)slf4j-api-1.7.6.jar(必选)
下载地址:http://www.slf4j.org/download.html
Spring slf4j 1个包:
(1)logback-ext-spring-0.1.2.jar(必选)
二进制包下载地址:http://maven.outofmemory.cn/org.logback-extensions/logback-ext-spring/0.1.2/
源码:https://github.com/qos-ch/logback-extensions
loback3个包:
(2)logback-core-1.1.7.jar(必选)
(3)logback-classic-1.1.7.jar(必选)
(4)logback-access-1.1.7.jar(可选)
下载地址:http://logback.qos.ch/download.html
附:
输出格式参考:http://logback.qos.ch/manual/layouts.html
简要参考:
lo {length }
logger {length } 输出日志的logger名,可有一个整形参数,功能是缩短logger名,设置为0表示只输入logger最右边点符号之后的字符串。
C {length }
class {length } 输出执行记录请求的调用者的全限定名。参数与上面的一样。尽量避免使用,除非执行速度不造成任何问题。contextName
cn 输出上下文名称。d {pattern }
date {pattern } 输出日志的打印日志,模式语法与java.text.SimpleDateFormat 兼容。
例如, %caller{2} 输出为:
0 [main] DEBUG - logging statement Caller+0 at mainPackage.sub.sample.Bar.sampleMethodName(Bar.java:22)Caller+1 at mainPackage.sub.sample.Bar.createLoggingRequest(Bar.java:17)
例如, %caller{3} 输出为:
16 [main] DEBUG - logging statement Caller+0 at mainPackage.sub.sample.Bar.sampleMethodName(Bar.java:22)Caller+1 at mainPackage.sub.sample.Bar.createLoggingRequest(Bar.java:17)Caller+2 at mainPackage.ConfigTester.main(ConfigTester.java:38)L / line输出执行日志请求的行号。尽量避免使用,除非执行速度不造成任何问题。m / msg / message
输出应用程序提供的信息。
M / method输出执行日志请求的方法名。尽量避免使用,除非执行速度不造成任何问题。n输出平台先关的分行符“\n”或者“\r\n”。p / le / level输出日志级别。r / relative输出从程序启动到创建日志记录的时间,单位是毫秒t / thread输出产生日志的线程名。replace(p ){r, t}p 为日志内容,r 是正则表达式,将p 中符合r 的内容替换为t 。
例如, "%replace(%msg){'\s', ''}"
- logback 日志级别不可控问题解决
- slf4j + logback 过滤日志级别
- SpringBoot Logback根据日志级别分离日志
- logback 配置不同级别日志输出
- logback之debug级别日志性能
- activemq使用logback作为日志问题解决
- spring4 使用logback不打印日志
- logback 日志不输出到指定文件
- logback冲突导致日志级别失效的解决办法
- logback动态设置某个类的日志级别
- spring boot +logback实现error级别日志报警
- spring boot + spring cloud日志级别的配置logback.xml
- 十五、不可控组件
- 不可控的世界,可控的意志力
- logback日志
- logback日志
- jboss logback slf4j 日志文件不生成问题
- mybatis用logback日志不显示sql的解决办法
- 扩展名获取
- 题目266 字符串逆序输出
- 词法分析
- 解决nginx负载均衡的session共享问题
- CNN基础和进展(上)
- logback 日志级别不可控问题解决
- Python Requests 操作指南
- 十六、Hadoop1.0伪集群安装(上)
- 微信公众平台开发入门教程(SAE方倍工作室)
- HttpClient 4.5使用(一)
- android studio gridlayout拼图游戏(一)让图片完整显示
- redis DB Key Value design
- gsoap使用示例
- 113. Path Sum II