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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容