Author: michiel
Date: 2010-07-09 15:28:19 +0200 (Fri, 09 Jul 2010)
New Revision: 42841

Modified:
   
mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/SimpleTimeStampImpl.java
Log:
a bit more configuration possibilities

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-07-09 13:27:49 UTC (rev 42840)
+++ 
mmbase/trunk/utils/src/main/java/org/mmbase/util/logging/SimpleTimeStampImpl.java
   2010-07-09 13:28:19 UTC (rev 42841)
@@ -12,6 +12,7 @@
 import java.io.PrintStream;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 
@@ -25,10 +26,10 @@
 
 public class SimpleTimeStampImpl extends AbstractSimpleImpl implements Logger {
 
-    private static SimpleTimeStampImpl root = new SimpleTimeStampImpl("");
-    private static Map<Level, PrintStream> ps = new HashMap<Level, 
PrintStream>();
 
-    static {
+    private  Map<Level, PrintStream> ps = new HashMap<Level, PrintStream>();
+
+    {
         for (Level l : Level.getLevels()) {
             if (l.toInt() >= Level.WARN.toInt()) {
                 ps.put(l, System.err);
@@ -42,6 +43,11 @@
 
     private static final DateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS ");
     private static Map<String, SimpleTimeStampImpl> loggers  = new 
ConcurrentHashMap<String, SimpleTimeStampImpl>();
+    private static SimpleTimeStampImpl root = new SimpleTimeStampImpl("");
+    static {
+        loggers.put("", root);
+    }
+    private static List<Map.Entry<String, String>> configurations = new 
CopyOnWriteArrayList<Map.Entry<String, String>>();
 
     private final String name;
 
@@ -51,6 +57,11 @@
             impl = new SimpleTimeStampImpl(name);
             impl.level = root.level;
             loggers.put(name, impl);
+            for (Map.Entry<String, String> conf : configurations) {
+                if (name.startsWith(conf.getKey())) {
+                    impl.conf(conf.getValue());
+                }
+            }
         }
         return impl;
     }
@@ -64,19 +75,12 @@
         return ps.get(l);
     }
 
-    /**
-     * The configure method of this Logger implemenation.
-     *
-     * @param c A string, which can contain the output (stdout or
-     * stderr) and the priority (e.g. 'info')
-     */
 
     public static  void configure(String c) {
+        configure("", c);
+    }
 
-        if (c == null) {
-            return; // everything default
-        }
-
+    private void conf(String c) {
         StringTokenizer t    = new StringTokenizer(c, ",");
         while (t.hasMoreTokens()) {
             String token = t.nextToken();
@@ -91,29 +95,51 @@
                 }
             }
             if (token.equals("trace")) {
-                root.setLevel(Level.TRACE);
+                setLevel(Level.TRACE);
             }
             if (token.equals("debug")) {
-                root.setLevel(Level.DEBUG);
+                setLevel(Level.DEBUG);
             }
             if (token.equals("service")) {
-                root.setLevel(Level.SERVICE);
+                setLevel(Level.SERVICE);
             }
             if (token.equals("info")) {
-                root.setLevel(Level.INFO);
+                setLevel(Level.INFO);
             }
             if (token.equals("warn")) {
-                root.setLevel(Level.WARN);
+                setLevel(Level.WARN);
             }
             if (token.equals("error")) {
-                root.setLevel(Level.ERROR);
+                setLevel(Level.ERROR);
             }
             if (token.equals("fatal")) {
-                root.setLevel(Level.FATAL);
+                setLevel(Level.FATAL);
             }
         }
     }
 
+    /**
+     * The configure method of this Logger implemenation.
+     *
+     * @param c A string, which can contain the output (stdout or
+     * stderr) and the priority (e.g. 'info')
+     */
+
+    public static  void configure(String prefix, String c) {
+
+        if (c == null) {
+            return; // everything default
+        }
+        configurations.add(new AbstractMap.SimpleEntry<String, String>(prefix, 
 c));
+
+        for (Map.Entry<String, SimpleTimeStampImpl> entry : 
loggers.entrySet()) {
+            if (entry.getKey().startsWith(prefix)) {
+                SimpleTimeStampImpl logger = entry.getValue();
+                logger.conf(c);
+            }
+        }
+    }
+
     @Override
     protected final void log (String s, Level l) {
         PrintStream stream = getStream(l);

_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to