logback配置备忘
资源pom.xml
a.slf4j/logback 组合(logback.xml)
b.slf4j/log4j组合(log4j.properties or log4j.xml)
c.如果是已用了commons-logging/log4j想用用slf4j/logback,那也容易用下面的配置
<
properties
>
< slf4j .version >1.7.1 </ slf4j.version >
< log4j .version >1.2.17 </ log4j.version >
< logback .version >1.0.1 </ logback.version >
</ properties >
< dependencyManagement >
< dependencies >
<!-- logging related -->
<!-- slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
< version >${slf4j.version} </ version >
</ dependency >
<!-- common-logging 实际调用slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >jcl-over-slf4j </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
<!-- java.util.logging 实际调用slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >jul-to-slf4j </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
<!-- slf4j-log4j绑定 -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-log4j12 </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >log4j-over-slf4j </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
<!-- logback -->
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-core </ artifactId >
< version >${logback.version} </ version >
< scope >runtime </ scope >
< optional >true </ optional >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-classic </ artifactId >
< scope >runtime </ scope >
< version >${logback.version} </ version >
< optional >true </ optional >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-access </ artifactId >
< version >${logback.version} </ version >
< scope >runtime </ scope >
< optional >true </ optional >
</ dependency >
</ dependencies >
</ dependencyManagement >
< slf4j .version >1.7.1 </ slf4j.version >
< log4j .version >1.2.17 </ log4j.version >
< logback .version >1.0.1 </ logback.version >
</ properties >
< dependencyManagement >
< dependencies >
<!-- logging related -->
<!-- slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
< version >${slf4j.version} </ version >
</ dependency >
<!-- common-logging 实际调用slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >jcl-over-slf4j </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
<!-- java.util.logging 实际调用slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >jul-to-slf4j </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
<!-- slf4j-log4j绑定 -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-log4j12 </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >log4j-over-slf4j </ artifactId >
< version >${slf4j.version} </ version >
< scope >runtime </ scope >
</ dependency >
<!-- logback -->
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-core </ artifactId >
< version >${logback.version} </ version >
< scope >runtime </ scope >
< optional >true </ optional >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-classic </ artifactId >
< scope >runtime </ scope >
< version >${logback.version} </ version >
< optional >true </ optional >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-access </ artifactId >
< version >${logback.version} </ version >
< scope >runtime </ scope >
< optional >true </ optional >
</ dependency >
</ dependencies >
</ dependencyManagement >
a.slf4j/logback 组合(logback.xml)
<!--
slf4j
-->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-core </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-classic </ artifactId >
</ dependency >
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-core </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-classic </ artifactId >
</ dependency >
b.slf4j/log4j组合(log4j.properties or log4j.xml)
<!--
slf4j
-->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
</ dependency >
<!-- log4j -->
< dependency >
< groupId >log4j </ groupId >
< artifactId >log4j </ artifactId >
</ dependency >
<!-- slf4j-log4j绑定 -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-log4j12 </ artifactId >
</ dependency >
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
</ dependency >
<!-- log4j -->
< dependency >
< groupId >log4j </ groupId >
< artifactId >log4j </ artifactId >
</ dependency >
<!-- slf4j-log4j绑定 -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-log4j12 </ artifactId >
</ dependency >
c.如果是已用了commons-logging/log4j想用用slf4j/logback,那也容易用下面的配置
<!--
slf4j
-->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
</ dependency >
<!-- common-logging 实际调用slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >jcl-over-slf4j </ artifactId >
</ dependency >
<!-- log4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >log4j-over-slf4j </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-core </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-classic </ artifactId >
</ dependency >
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >slf4j-api </ artifactId >
</ dependency >
<!-- common-logging 实际调用slf4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >jcl-over-slf4j </ artifactId >
</ dependency >
<!-- log4j -->
< dependency >
< groupId >org.slf4j </ groupId >
< artifactId >log4j-over-slf4j </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-core </ artifactId >
</ dependency >
< dependency >
< groupId >ch.qos.logback </ groupId >
< artifactId >logback-classic </ artifactId >
</ dependency >
再到http://logback.qos.ch/translator/Welcome.do,將你原來的log4j.properties转成logback.xml
就可以將commons-logging.jar 跟 log4j.jar自你系統中移除了