logger.java

来自「一个网络爬虫」· Java 代码 · 共 75 行

JAVA
75
字号
package org.flaviotordini.arale;import java.util.*;import java.io.*;/** *  Classe che si occupa del logging. * *@author     Flavio Tordini *@created    7 novembre 2001 */public class Logger {    /**     *  Description of the Field     *     *@since     */    public PrintStream logger = null;    /**     *  Sets the logFile attribute of the Logger object     *     *@param  filename  The new logFile value     *@since     */    public void setLogFile(String filename) {        File logfile = new File(filename);        System.out.println("Setting log file to " + logfile);        try {            FileOutputStream fos = new FileOutputStream(logfile.toString(), false);            logger = new PrintStream(fos, true);            logger.println("Arale started at " + new java.util.Date());        } catch (Exception e) {            e.printStackTrace();            System.out.println("Error setting log file");        }    }    /**     *  Description of the Method     *     *@param  s  Description of Parameter     *@since     */    public void log(String s) {        s = "[" + Thread.currentThread().getName() + "] " + s;        System.out.println(s);        logger.println(s);    }    /**     *  Description of the Method     *     *@param  e  <...>     *@since     27 novembre 2001     */    public void log(Exception e) {        // log(e.toString());        e.printStackTrace(logger);        System.out.println(e.toString());    }}

⌨️ 快捷键说明

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