KickJava   Java API By Example, From Geeks To Geeks.

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


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
15 /**
16  * A very simple implementation of Logger. It writes everything to
17  * standard output or standard error (the configure string can contain
18  * `stderr' or `stdout' (default)). It does not know categories (and
19  * therefore is a Singleton class). It is possible to configure what
20  * should be logged as well (with a level-string token in the
21  * configure string).
22  *
23  * @author Michiel Meeuwissen
24  * @version $Id: SimpleImpl.java,v 1.12 2005/10/02 16:42:15 michiel Exp $
25  * @since MMBase-1.4
26  */

27
28 public class SimpleImpl extends AbstractSimpleImpl implements Logger {
29
30     private static SimpleImpl root = new SimpleImpl();
31     private static PrintStream JavaDoc ps = System.out;
32
33     private SimpleImpl() {
34         // a Singleton class.
35
}
36
37     public static SimpleImpl 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(s);
89     }
90
91 }
92
Popular Tags