不同类输出到不同文件

log4j.rootLogger=INFO
log4j.logger.com.my.haha.hello.A=INFO,A1
log4j.logger.com.my.haha.hello.B=INFO,A2
log4j.logger.com.my.haha.hello.C=INFO,A3

log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=c:/logs/test-a1.log
log4j.appender.A1.MaxFileSize=500KB
log4j.appender.A1.MaxBackupIndex=50
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.File=c:/logs/test-a2.log
log4j.appender.A2.MaxFileSize=500KB
log4j.appender.A2.MaxBackupIndex=50
log4j.appender.A2.Append=true
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.File=c:/logs/test-a3.log
log4j.appender.A3.MaxFileSize=500KB
log4j.appender.A3.MaxBackupIndex=50
log4j.appender.A3.Append=true
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n

 

 

 

 

 

 

 

 

 

 

package com.my.haha.hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class A {
    public  void log() {
        Log log = LogFactory.getLog(A.class);
        log.info("Log in A");
    }
}

 

 

 

package com.my.haha.hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class B {
    public  void log() {
        Log log = LogFactory.getLog(B.class);
        log.info("Log in B");
    }
}

 

 

package com.my.haha.hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C {
    public  void log() {
        Log log = LogFactory.getLog(C.class);
        log.info("Log in C");
    }
}

 

 

package com.my.haha.hello;

public class Test {
    public static void main(String[] args) {
        A a = new A();
        B b = new B();
        C c = new C();
        a.log();
        b.log();
        c.log();
    }
}

你可能感兴趣的:(apache,C++,c,log4j,C#)