chris@0: /* chris@0: * StarOffice News Server chris@0: * see AUTHORS for the list of contributors chris@0: * chris@0: * This program is free software: you can redistribute it and/or modify chris@0: * it under the terms of the GNU General Public License as published by chris@0: * the Free Software Foundation, either version 3 of the License, or chris@0: * (at your option) any later version. chris@0: * chris@0: * This program is distributed in the hope that it will be useful, chris@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@0: * GNU General Public License for more details. chris@0: * chris@0: * You should have received a copy of the GNU General Public License chris@0: * along with this program. If not, see . chris@0: */ chris@0: chris@0: package com.so.news; chris@0: chris@0: import java.io.FileOutputStream; chris@0: import java.io.IOException; chris@0: import java.io.PrintStream; chris@0: import java.util.Date; chris@0: chris@0: /** chris@0: * Provides logging and debugging methods. chris@0: * @author Christian Lins chris@0: */ chris@0: public class Debug chris@0: { chris@0: private static Debug instance = null; chris@0: chris@0: /** chris@0: * Returns the singelton instance of this class. chris@0: */ chris@0: public static Debug getInstance() chris@0: { chris@0: if(instance == null) chris@0: instance = new Debug(); chris@0: chris@0: return instance; chris@0: } chris@0: chris@0: private PrintStream out = System.err; chris@0: chris@0: /** chris@0: * This class is a singelton class. The constructor is private to prevent chris@0: * the creation of more than one instance. chris@0: */ chris@0: private Debug() chris@0: { chris@0: try chris@0: { chris@0: String filename = Config.getInstance().get(Config.CONFIG_N3TPD_LOGFILE, "n3tpd.log"); chris@0: chris@0: this.out = new PrintStream(new FileOutputStream(filename)); chris@0: } chris@0: catch(IOException e) chris@0: { chris@0: e.printStackTrace(); chris@0: } chris@0: } chris@0: chris@0: /** chris@0: * Returns the debug output PrintStream. By default this is System.err. chris@0: */ chris@0: public PrintStream getStream() chris@0: { chris@0: return out; chris@0: } chris@0: chris@0: /** chris@0: * Writes the given message to the debug output. chris@0: * @param msg A String message or an object. chris@0: */ chris@0: public void log(Object msg) chris@0: { chris@0: log(out, msg); chris@0: log(System.out, msg); chris@0: } chris@0: chris@0: /** chris@0: * Writes the given debug message to the given PrintStream. chris@0: * @param out chris@0: * @param msg chris@0: */ chris@0: public void log(PrintStream out, Object msg) chris@0: { chris@0: out.print(new Date().toString()); chris@0: out.print(": "); chris@0: out.println(msg.toString()); chris@0: out.flush(); chris@0: } chris@0: }