如何在使用slf4j时使用domconfigurator for log4j?

n7taea2i  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(208)

我正在尝试将slf4j与log4j一起使用,并且在使用log4j配置xml时遇到了一些困难。如何将log4j的config xmls与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>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题