[原创]slf4j+logback 的详细配置

1.类库:

logback-classic-0.9.28.jar

logback-core-0.9.28.jar

slf4j-api-1.6.1.jar

 

2.logback.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
	debug="true" 	启动时输出配置加载信息
	scan="true" 	默认每分钟自动扫描
	scanPeriod="30 seconds" 	设置每30秒自动扫描,若没有指定具体单位则以milliseconds为标准(单位:milliseconds, seconds, minutes or hours)
-->
<configuration scan="true" scanPeriod="2 seconds">

	<contextName>MacroteaLogging</contextName>
	
	<property name="tip" value="信息:" />
	<!--tomcat webapps路径-->
	<property name="logback.logs.path" value="D:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\" />
	<!--项目名(我是直接在ROOT)-->
	<property name="logback.project.name" value="ROOT" />
	<!--日志模块名(如:默认(default),销售(sales),订单(orders)...)-->
	<property name="logback.logs.module.name" value="default" />
	
	<timestamp key="byDay" datePattern="yyyyMMdd"/>
	
	<!--appender 模块-->
	<appender name="console" class="ch.qos.logback.core.ConsoleAppender" target="System.err">
		<encoder charset="UTF-8">
			<pattern>%n[%level] - %date - %logger#%line%n ${tip} %msg%n</pattern>
		</encoder>
		<target>System.err</target>
	</appender>
	
	<appender name="file" class="ch.qos.logback.core.FileAppender">
		<file>${logback.logs.path}${logback.project.name}\\WEB-INF\\${logback.logs.module.name}\\log_${byDay}.log</file>
		<encoder charset="UTF-8">
			<pattern>%n[%level] - %date - %logger#%line%n ${tip} %msg%n</pattern>
		</encoder>
	</appender>
	
	<!--logger 模块-->
	<logger name="com.mtea.shop.test" level="INFO">
		<appender-ref ref="file" />
	</logger>
	<!--pager-->
	<logger name="com.mtea.shop.model.ext" level="DEBUG"/>
	<!--service impl-->
	<logger name="com.mtea.shop.service.impl" level="DEBUG"/>
	
	<!--SSH2-->
	<logger name="org.springframework" level="ERROR"/>
	<logger name="org.hibernate" level="ERROR"/>
	<logger name="org.apache.struts2" level="ERROR"/>
	<logger name="com.opensymphony" level="ERROR"/>
	<!--C3P0-->
	<logger name="com.mchange" level="ERROR"/>
	
	<root level="DEBUG">
		<appender-ref ref="console" />
	</root>
</configuration>

<!--
<root level="OFF">
${HOSTNAME}
%contextName
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>

-->

你可能感兴趣的:(apache,tomcat,Hibernate,xml,ext)