KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > logging > SimpleTimeStampImpl


1 /*
2 This software is OSI Certified Open Source Software.
3 OSI Certified is a certification mark of the Open Source Initiative.
4
5 The license (Mozilla version 1.0) can be read at the MMBase site.
6 See http://www.MMBase.org/license
7
8 */

9
10 package org.mmbase.util.logging;
11
12 import java.io.PrintStream JavaDoc;
13 import java.util.StringTokenizer JavaDoc;
14 import java.text.DateFormat JavaDoc;
15 import java.text.SimpleDateFormat JavaDoc;
16
17 /**
18  * Like SimpleImpl, but also adds timestamps.
19  *
20  * @author Michiel Meeuwissen
21  * @version $Id: SimpleTimeStampImpl.java,v 1.3 2005/10/02 16:42:15 michiel Exp $
22  * @since MMBase-1.7
23  */

24
25 public class SimpleTimeStampImpl extends AbstractSimpleImpl implements Logger {
26
27     private static SimpleTimeStampImpl root = new SimpleTimeStampImpl();
28     private static PrintStream JavaDoc ps = System.out;
29
30     private static final DateFormat JavaDoc dateFormat = new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ss,SSS ");
31
32
33     private SimpleTimeStampImpl() {
34         // a Singleton class.
35
}
36
37     public static SimpleTimeStampImpl getLoggerInstance(String JavaDoc name) {
38         return root;
39     }
40
41     /**
42      * The configure method of this Logger implemenation.
43      *
44      * @param c A string, which can contain the output (stdout or
45      * stderr) and the priority (e.g. 'info')
46      */

47
48     public static void configure(String JavaDoc c) {
49
50         if (c == null) {
51             return; // everything default
52
}
53
54         StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(c, ",");
55         while (t.hasMoreTokens()) {
56             String JavaDoc token = t.nextToken();
57             if (token.equals("stderr")) {
58                 ps = System.err;
59             }
60             if (token.equals("stdout")) {
61                 ps = System.out;
62             }
63             if (token.equals("trace")) {
64                 root.setLevel(Level.TRACE);
65             }
66             if (token.equals("debug")) {
67                 root.setLevel(Level.DEBUG);
68             }
69             if (token.equals("service")) {
70                 root.setLevel(Level.SERVICE);
71             }
72             if (token.equals("info")) {
73                 root.setLevel(Level.INFO);
74             }
75             if (token.equals("warn")) {
76                 root.setLevel(Level.WARN);
77             }
78             if (token.equals("error")) {
79                 root.setLevel(Level.ERROR);
80             }
81             if (token.equals("fatal")) {
82                 root.setLevel(Level.FATAL);
83             }
84         }
85     }
86
87     protected final void log (String JavaDoc s) {
88         ps.println(dateFormat.format(new java.util.Date JavaDoc()) + s);
89     }
90
91 }
92
Popular Tags