including openisis 0.9.0 into webpac tree
[webpac] / openisis / org / openisis / Log.java
diff --git a/openisis/org/openisis/Log.java b/openisis/org/openisis/Log.java
new file mode 100644 (file)
index 0000000..bc39894
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+       openisis - an open implementation of the CDS/ISIS database
+       Version 0.8.x (patchlevel see file Version)
+       Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library 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
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+       see README for more information
+EOH */
+
+package org.openisis;
+
+import java.io.*;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
+/**
+       Logger.
+<p>
+       $Id: Log.java,v 1.1 2003/04/12 14:48:21 mawag Exp $
+       @version $Revision: 1.1 $
+       @author  $Author: mawag $
+*/
+public class Log {
+
+       /** Error log level */
+       public static final int ERROR = 1;
+       /**     Warning log level */
+       public static final int WARN = ERROR + 1;
+       /** Info log level */
+       public static final int INFO = WARN + 1;
+       /**     Verbose log level */
+       public static final int VERBOSE = INFO + 1;
+
+       private static SimpleDateFormat TheFormat =
+               new SimpleDateFormat ("yyMMddHHmmss");
+
+       private static PrintStream TheStream = System.err;
+
+       private static int TheLevel = VERBOSE;
+
+       /**     Set log level. Default level is VERBOSE.
+       */
+       public static void setLevel (int lvl) {
+               TheLevel = lvl;
+       }
+
+       private static void doPrint (
+               String pref, Object that, String msg, Throwable ex
+       ) {
+               StringBuffer buf = new StringBuffer (128);
+               buf.append (pref).
+                       append (' ').
+                       append (TheFormat.format (new Date ())).
+                       append (' ');
+               if (null != that) {
+                       buf.append ('[').
+                               append (that).
+                               append (']');
+               }
+               if (null != msg) {
+                       if (null != that) {
+                               buf.append (": ");
+                       }
+                       buf.append (msg);
+               }
+               if (null != ex) {
+                       if (null != that || null != msg) {
+                               buf.append (": ");
+                       }
+               }
+               synchronized (TheStream) {
+                       TheStream.print (buf.toString ());
+                       if (null != ex) {
+                               ex.printStackTrace (TheStream);
+                       }
+                       else {
+                               TheStream.println ();
+                       }
+               }
+       }
+
+       /**     Log a verbose message.
+       */
+       public static void verbose (Object module, String msg, Throwable ex) {
+               if (VERBOSE <= TheLevel) {
+                       doPrint ("    ", module, msg, ex);
+               }
+       }
+
+       /**     Log an info message.
+       */
+       public static void info (Object module, String msg, Throwable ex) {
+               if (INFO <= TheLevel) {
+                       doPrint ("*** ", module, msg, ex);
+               }
+       }
+
+       /**     Log a warning.
+       */
+       public static void warn (Object module, String msg, Throwable ex) {
+               if (WARN <= TheLevel) {
+                       doPrint ("WARN", module, msg, ex);
+               }
+       }
+
+       /**     Log an error.
+       */
+       public static void error (Object module, String msg, Throwable ex) {
+               if (ERROR <= TheLevel) {
+                       doPrint ("ERR ", module, msg, ex);
+               }
+       }
+
+/*
+       Tester
+       public static void main (String argv[]) {
+               error (new Object (), "error", new Error ("fatal"));
+               warn (null, "warning", null);
+               info (null, null, null);
+               verbose (new Exception (), null, new Exception ());
+       }
+*/
+}
+