我正在尝试将slf4j与log4j一起使用,我在使用log4j config xml时遇到了一些困难。我如何使用配置xmls for log4j与slf4j。请指导我。
LoggerImpl实现类:
package com.cisco.logger.LoggerFramework;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggerImpl implements ILogger {
public Logger getLogger(Class name) {
Logger logger = LoggerFactory.getLogger(name);
return logger;
}
}
Log4j配置XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: log4j.xml,v 1.1.1.1 2005/11/12 20:08:29 gmoran Exp $ -->
<!--
| For more configuration information and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A time/date based rolling appender -->
<appender name="LOGGERFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="/apps/pentaho_nfs/installbase/input/poc/applogger.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<!-- Rollover at the top of each hour
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
-->
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LOGGERFILE"/>
</root>
</log4j:configuration>