Management of log files

xiaoxiao2021-03-06  77

// 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 log = logger.getlogger ("writelog.jbwritelog"); // File path diagonal char XG = java.io.file .separatorChar; / ** * constructor: and setting configuration file * @param propertyFile: profile path * / public JBWriteLog (String propertyFile) throws Exception {PropertyConfigurator.configure (propertyFile);} / ** * * @ write operation log Param loginfo: Log an entry * @throws exception * / public void writelog (string loginfo) throws exception {TRY {// introduced normal information log configuration file //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 ("/ property / log4j.properties); wl.writelog (" 1 "); Wl.writelog (" 2 "); Wl.writelog ("3"); wl.writelog ("4");} catch (exception e) {E.PrintStackTrace ();}}

}

转载请注明原文地址:https://www.9cbs.com/read-93886.html

New Post(0)