⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logger.java

📁 java web 开发,Java Xml 编程指南书籍源码
💻 JAVA
字号:
package MyNa.utils;
// logger class

import java.io.*;

public class Logger { // may be shared across threads.
  static String fileProp="MyNa.utils.Logger.file";
  static String debugProp="MyNa.utils.Logger.debugLevel";
  static String defaultFileName="dbLog.log";
  String fileName;
  int debugLevel; // simply on or off, in this version;
        // we use separate Logger objects for err, admin.

public Logger(String fName){
  fileName=fName;
  debugLevel=Integer.parseInt(System.getProperty(debugProp,"1"));
  }

public Logger(){this(System.getProperty(fileProp,defaultFileName));}

public synchronized void setFileName(String fName){fileName=fName;}
public synchronized void setDebugLevel(int N){debugLevel=N;}
public synchronized void setDebug(boolean B){debugLevel=B?1:0;}
public synchronized void setDebug(String S){
  setDebug((new Boolean(S)).booleanValue());
}

public synchronized void clearLog(){ 
  if(debugLevel<=0)return;
  try{
    PrintWriter f=new PrintWriter(new FileWriter(fileName,true));
    String S=MiscDate.todaysDate();
    f.println(S);
    f.close();
  }catch(IOException e){}
}

public synchronized void logIt(String S){
  if(debugLevel<=0)return;
  try{
    PrintWriter f=new PrintWriter(new FileWriter(fileName,true));
    f.println(S);
    f.close();
    }catch(IOException e){}
}
public synchronized void logIt(String S,Throwable ex){ 
  if(debugLevel<=0)return;
  try{
    PrintWriter f=new PrintWriter(new FileWriter(fileName,true));
    f.println(S);
    ex.printStackTrace(f);
    f.close();
    }catch(IOException e){}
}

public static String stackTrace(Throwable ex){
    StringWriter sw=new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -