log4j中不同类输出到不同文件

现在有一个类:net.trustie.task.Test ,想把在这个类中的日志输出到一个独立的文件。

可以这么做:

首先,在net.trustie.task.Test类中定义:

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

private static Log logger= LogFactory.getLog("test");

然后配置文件log4j.xml:


        
        
        
        
        
            
        


        
        

通过配置,在Test类中,所有通过logger.info的日志输出都会到./log/test.log中。

你可能感兴趣的:(engineering)