/** * @(#)gnsd.java 1.0.1 98/12/20 *

* Copyright (C) 1998 David E. Wexler *

* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. See * license.txt for a full copy of the GNU GPL. *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *

* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. *

* To Contact the author send e-mail to vagabond@netdragon.com or send * snailmail to: 511 Bobcat Ct, Punta Gorda, FL 3398. */ import java.io.*; import java.util.*; import java.util.Date.*; import gnsd; /** * logger - makes sure that all important commands are logged. *

* Will cause all major commands (@connect, @login, @join, @joinnew, * @list, @part, and @logout) to be logged to a file. If we are in * a debug mode, these will also be echoed to the screen. * * @author David Wexler (vagabond@netdragons.com) * @version 1.0.1 * @since gnsd.1.0.1 */ public class logger { /** * path to data directory */ String PATH; /** * Stores current time and data. This is used to timestamp each even with * time_t (seconds since ephoc Jan 1, 1970, 12:00am). */ Date d; /** * The File we are outputting to. */ FileOutputStream file; /** * Sets up a PrintStream so we can just print the data without playing with * bytes. */ PrintStream data; /** * Stores the current debug state. */ boolean debug; /** * Creates and instance of the logger class. All needed information is * passed into via this constructor. * * @param d are we in dubug mode? * @param s Instance of the server so we can get runtime info. * @param name name of the output file. * @see #setup(java.lang.String) * @since gnsd.1.0.1 */ public logger (boolean d, gnsd s, String name) { PATH = s.getPath(); debug = d; setup(name); } /** * Creates and instance of the logger class. All needed information is * passed into via this constructor. This is just like the other * constructor, but is assumes a file name of "access_log". * * @param d are we in dubug mode? * @param s Instance of the server so we can get runtime info. * @see #logger(boolean, gnsd, java.util.String) * @see #setup(java.lang.String) * @since gnsd.1.0.1 */ public logger (boolean d, gnsd s) { PATH = s.getPath(); debug = d; setup("access_log"); } /** * Prints the given message to the log. All data is timestamped via time_t. * If we are in a dubug mode, it will also echo to the screen. * * @param msg the message to print. * @since gnsd.1.0.1 */ public void print(String msg) { d = new Date(); data.print("\n" + d.getTime() + " " + msg); if (debug) System.out.println(d.getTime() + " " + msg); } /** * Allows any class with a instance of logger to determing if we are * in a debug state. * * @return true if we are debugging, false otherwise. * @since gnsd.1.0.1 */ public boolean debug() { return debug; } /** * Opens a copy of the file and keeps it open. This is just like any other * server. The file is open at start-up and is kept open until the server * is shut down. * * @param name file name to save the log in. * @since gnsd.1.0.1 */ private void setup(String name) { try { file = new FileOutputStream(PATH + "/log/" + name); data = new PrintStream(file); } catch (IOException ex) { System.err.println("Warning: Could not open Log file!"); } } }