美文网首页工作中源代码学习
SLF4J、Log4j、Logback三者之间的关系

SLF4J、Log4j、Logback三者之间的关系

作者: ___TheOne___ | 来源:发表于2018-06-15 17:38 被阅读27次

1.SLF4J、Log4j、Logback三者之间的关系

SLF4J是中日志设计的门面模式,而Log4j和Logback是日志框架的具体实现。

2.Spring项目,自定义日志配置文件加载位置

Web Application

If using Spring in a web application, add the following servlet context listener declaration to web.xml:

<listener>
    <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
</listener>

This will start up the Logback environment and shut it down in sync with your web application's lifecycle. This listener should be registered before ContextLoaderListener in web.xml, when using custom Logback initialization. For Servlet 2.2 containers and Servlet 2.3 ones that do not initialize listeners before servlets, use LogbackConfigServlet. See the LogbackConfigListener and WebLogbackConfigurer javadoc for details.

If you want to specify the logback.xml config file in a location other than the default (root of the classpath), you can specify its location using a Spring resource path with system propertyplaceholders in a logbackConfigLocation servlet context param in web.xml:

<context-param>
    <param-name>logbackConfigLocation</param-name>
    <param-value>/WEB-INF/logback-${os.name}.xml</param-value>
</context-param>

3.参考文章

1.slf4j log4j logback关系详解和相关用法
2.【飞天奔月出品】剖析logback4:spring LogbackConfigListener

相关文章

网友评论

    本文标题:SLF4J、Log4j、Logback三者之间的关系

    本文链接:https://www.haomeiwen.com/subject/albmeftx.html