Author: michiel
Date: 2010-06-17 14:24:02 +0200 (Thu, 17 Jun 2010)
New Revision: 42592

Modified:
   mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/Level.java
   
mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/SimpleTimeStampImpl.java
Log:
simple chnage, made on default WARN and higher log to stderr

Modified: mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/Level.java
===================================================================
--- mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/Level.java 
2010-06-17 12:23:31 UTC (rev 42591)
+++ mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/Level.java 
2010-06-17 12:24:02 UTC (rev 42592)
@@ -48,6 +48,13 @@
         FATAL   = new Level(FATAL_INT, "FATAL"),
         OFF     = new Level(OFF_INT, "OFF");
 
+    /**
+     * @since MMBase-2.0
+     */
+    public static Level[] getLevels() {
+        return new Level[] { TRACE, DEBUG, SERVICE, INFO, WARN,ERROR, FATAL, 
OFF};
+    }
+
     private int level;
     private String string;
 

Modified: 
mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/SimpleTimeStampImpl.java
===================================================================
--- 
mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/SimpleTimeStampImpl.java
   2010-06-17 12:23:31 UTC (rev 42591)
+++ 
mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/SimpleTimeStampImpl.java
   2010-06-17 12:24:02 UTC (rev 42592)
@@ -10,8 +10,7 @@
 package org.mmbase.util.logging;
 
 import java.io.PrintStream;
-import java.util.StringTokenizer;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -27,8 +26,20 @@
 public class SimpleTimeStampImpl extends AbstractSimpleImpl implements Logger {
 
     private static SimpleTimeStampImpl root = new SimpleTimeStampImpl("");
-    private static PrintStream ps = System.out;
+    private static Map<Level, PrintStream> ps = new HashMap<Level, 
PrintStream>();
 
+    static {
+        for (Level l : Level.getLevels()) {
+            if (l.toInt() >= Level.WARN.toInt()) {
+                ps.put(l, System.err);
+            } else {
+                ps.put(l, System.out);
+            }
+        }
+    }
+
+    private static int stacktraceLevel  = Level.FATAL_INT;
+
     private static final DateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS ");
     private static Map<String, SimpleTimeStampImpl> loggers  = new 
ConcurrentHashMap<String, SimpleTimeStampImpl>();
 
@@ -49,6 +60,10 @@
     }
 
 
+    protected PrintStream getStream(Level l) {
+        return ps.get(l);
+    }
+
     /**
      * The configure method of this Logger implemenation.
      *
@@ -66,10 +81,14 @@
         while (t.hasMoreTokens()) {
             String token = t.nextToken();
             if (token.equals("stderr")) {
-                ps = System.err;
+                for (Level l : Level.getLevels()) {
+                    ps.put(l, System.err);
+                }
             }
             if (token.equals("stdout")) {
-                ps = System.out;
+                for (Level l : Level.getLevels()) {
+                    ps.put(l, System.out);
+                }
             }
             if (token.equals("trace")) {
                 root.setLevel(Level.TRACE);
@@ -96,8 +115,13 @@
     }
 
     @Override
-    protected final void log (String s) {
-        ps.println(dateFormat.format(new java.util.Date()) + s);
+    protected final void log (String s, Level l) {
+        PrintStream stream = getStream(l);
+        stream.println(l.toString() + " " + dateFormat.format(new 
java.util.Date()) + s);
+        if (l.toInt() >= stacktraceLevel) {
+            Throwable t = new Throwable();
+            stream.println(Logging.stackTrace(t));
+        }
     }
 
 }

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to