日期:2014-05-17  浏览次数:20839 次

log4j 一个线程记录一个日志如何配置?
现有一后台java程序,分四个线程去运行,想通过log4j 一个线程记录一个日志,如何搞? 求高人指教,谢谢!

------解决方案--------------------
Java code

public class ThreadLog1 extends Thread {
    private static Logger logger = Logger.getLogger("file_1");
    private boolean stop = false;
    public void run() {
        while(!stop){
            System.out.println("I am ThreadLog1");
            logger.info("I am ThreadLog1");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public boolean isStop() {
        return stop;
    }
    public void setStop(boolean stop) {
        this.stop = stop;
    }
}