////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import org.apache.log4j.*;
/** * @author * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class JBWriteLog { Logger log = Logger.getLogger("writelog.JBWriteLog"); Logger logE = Logger.getLogger("writelog.JBWriteLog"); //文件路径斜扛 char xg = java.io.File.separatorChar; /** * 构造函数:并设置配置文件 * @param PropertyFile:配置文件路径 */ public JBWriteLog(String PropertyFile) throws Exception{ PropertyConfigurator.configure(PropertyFile); } /** * 写日志操作 * @param logInfo:日志一个条目的内容 * @throws Exception */ public void writeLog(String logInfo) throws Exception{ try { //引入普通信息日志配置文件 //PropertyConfigurator.configure("."+xg+"properties"+xg+propertiesFileName);
log.info(logInfo); } catch (Exception e) {
e.printStackTrace(); throw e; } }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** * @author * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class TestLog { /** * Constructor */ public TestLog() { }
public static void main(String[] args) { try{ JBWriteLog wl = new JBWriteLog("/properties/log4j.properties"); wl.writeLog("1"); wl.writeLog("2"); wl.writeLog("3"); wl.writeLog("4"); }catch(Exception e) { e.printStackTrace(); }
}
}

|