01: /*
02: This software is OSI Certified Open Source Software.
03: OSI Certified is a certification mark of the Open Source Initiative.
04:
05: The license (Mozilla version 1.0) can be read at the MMBase site.
06: See http://www.MMBase.org/license
07:
08: */
09:
10: package org.mmbase.util.logging;
11:
12: import java.io.PrintStream;
13: import java.util.StringTokenizer;
14: import java.text.DateFormat;
15: import java.text.SimpleDateFormat;
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
26: Logger {
27:
28: private static SimpleTimeStampImpl root = new SimpleTimeStampImpl();
29: private static PrintStream ps = System.out;
30:
31: private static final DateFormat dateFormat = new SimpleDateFormat(
32: "yyyy-MM-dd HH:mm:ss,SSS ");
33:
34: private SimpleTimeStampImpl() {
35: // a Singleton class.
36: }
37:
38: public static SimpleTimeStampImpl getLoggerInstance(String name) {
39: return root;
40: }
41:
42: /**
43: * The configure method of this Logger implemenation.
44: *
45: * @param c A string, which can contain the output (stdout or
46: * stderr) and the priority (e.g. 'info')
47: */
48:
49: public static void configure(String c) {
50:
51: if (c == null) {
52: return; // everything default
53: }
54:
55: StringTokenizer t = new StringTokenizer(c, ",");
56: while (t.hasMoreTokens()) {
57: String token = t.nextToken();
58: if (token.equals("stderr")) {
59: ps = System.err;
60: }
61: if (token.equals("stdout")) {
62: ps = System.out;
63: }
64: if (token.equals("trace")) {
65: root.setLevel(Level.TRACE);
66: }
67: if (token.equals("debug")) {
68: root.setLevel(Level.DEBUG);
69: }
70: if (token.equals("service")) {
71: root.setLevel(Level.SERVICE);
72: }
73: if (token.equals("info")) {
74: root.setLevel(Level.INFO);
75: }
76: if (token.equals("warn")) {
77: root.setLevel(Level.WARN);
78: }
79: if (token.equals("error")) {
80: root.setLevel(Level.ERROR);
81: }
82: if (token.equals("fatal")) {
83: root.setLevel(Level.FATAL);
84: }
85: }
86: }
87:
88: protected final void log(String s) {
89: ps.println(dateFormat.format(new java.util.Date()) + s);
90: }
91:
92: }
|