日志文件的管理

类别:网站制作 点击:0 评论:0 推荐:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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();
           }

      }

}

本文地址:http://com.8s8s.com/it/it31210.htm