标签:
1 <properties> 2 <spring.version>4.1.0.RELEASE</spring.version> 3 <slf4j.version>1.7.13</slf4j.version> 4 </properties> 5 <!-- log4j --> 6 <dependency> 7 <groupId>org.springframework</groupId> 8 <artifactId>spring-core</artifactId> 9 <version>${spring.version}</version> 10 <exclusions> 11 <exclusion> 12 <groupId>commons-logging</groupId> 13 <artifactId>commons-logging</artifactId> 14 </exclusion> 15 </exclusions> 16 </dependency> 17 <dependency> 18 <groupId>org.slf4j</groupId> 19 <artifactId>jcl-over-slf4j</artifactId> 20 <version>${slf4j.version}</version> 21 </dependency> 22 <dependency> 23 <groupId>org.slf4j</groupId> 24 <artifactId>slf4j-api</artifactId> 25 <version>${slf4j.version}</version> 26 </dependency> 27 <dependency> 28 <groupId>org.slf4j</groupId> 29 <artifactId>slf4j-log4j12</artifactId> 30 <version>${slf4j.version}</version> 31 </dependency> 32 <dependency> 33 <groupId>log4j</groupId> 34 <artifactId>log4j</artifactId> 35 <version>1.2.17</version> 36 </dependency>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd"> 3 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 4 5 <!-- [控制台STDOUT] --> 6 <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> 7 <param name="encoding" value="UTF-8" /> 8 <param name="target" value="System.out" /> 9 <layout class="org.apache.log4j.PatternLayout"> 10 <param name="ConversionPattern" value="%-5p %c{2} - %m%n" /> 11 </layout> 12 </appender> 13 <!-- [公共Appender] --> 14 <appender name="DEFAULT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender"> 15 <param name="File" value="${webapp.root}/logs/common-default.log" /> 16 <param name="Append" value="true" /> 17 <param name="encoding" value="UTF-8" /> 18 <param name="DatePattern" value="‘.‘yyyy-MM-dd‘.log‘" /> 19 <layout class="org.apache.log4j.PatternLayout"> 20 <param name="ConversionPattern" value="%d %-5p %c{2} - %m%n" /> 21 </layout> 22 </appender> 23 <!-- [错误日志APPENDER] --> 24 <appender name="ERROR-APPENDER" class="org.apache.log4j.DailyRollingFileAppender"> 25 <param name="File" value="${webapp.root}/logs/common-error.log" /> 26 <param name="Append" value="true" /> 27 <param name="encoding" value="UTF-8" /> 28 <param name="threshold" value="error" /> 29 <param name="DatePattern" value="‘.‘yyyy-MM-dd‘.log‘" /> 30 <layout class="org.apache.log4j.PatternLayout"> 31 <param name="ConversionPattern" value="%d %-5p %c{2} - %m%n" /> 32 </layout> 33 </appender> 34 <!-- 由于用了springmvc框架,日志配置好后,会输出很多spring日志,在log4j.xml中,增加一段配置,修改spring包的日志输出级别 --> 35 <!-- 通过<category></category>的定义可以将各个包中的类日志输出到不同的日志文件中 --> 36 <category name="org.springframework"> 37 <priority value="error" /> 38 <appender-ref ref="CONSOLE" /> 39 </category> 40 <!-- Root Logger --> 41 <root> 42 <level value="${rootLevel}"></level> 43 <appender-ref ref="CONSOLE" /> 44 <appender-ref ref="DEFAULT-APPENDER" /> 45 <appender-ref ref="ERROR-APPENDER" /> 46 </root> 47 48 </log4j:configuration>
1 <!-- 配置加载log4j.xml文件路径 --> 2 <context-param> 3 <param-name>log4jConfigLocation</param-name> 4 <param-value>classpath:log4j.xml</param-value> 5 </context-param> 6 7 <!-- 配置log4j.xml变量 --> 8 <context-param> 9 <param-name>rootLevel</param-name> 10 <param-value>DEBUG</param-value> 11 </context-param> 12 13 <context-param> 14 <param-name>loggingLevel</param-name> 15 <param-value>INFO</param-value> 16 </context-param> 17 18 <listener> 19 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 20 </listener>
1 <renderer></renderer> 2 <appender></appender> 3 <plugin></plugin> 4 <logger></logger> 5 <category></category> 6 <root></root> 7 <loggerfactory></loggerfactory>> 8 <categoryfactory></categoryfactory>
我添加<category>的时候放在了<root>标签后,配置文件报错
标签:
原文地址:http://www.cnblogs.com/jason-peggy/p/5153428.html