SLF4J、Log4j、Logback三者之間的關(guān)系

1.SLF4J、Log4j、Logback三者之間的關(guān)系

SLF4J是中日志設(shè)計(jì)的門面模式,而Log4j和Logback是日志框架的具體實(shí)現(xiàn)。

2.Spring項(xiàng)目,自定義日志配置文件加載位置

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關(guān)系詳解和相關(guān)用法
2.【飛天奔月出品】剖析logback4:spring LogbackConfigListener

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容