01: package org.shiftone.cache.util;
02:
03: /**
04: * I'm not trying to reinvent Log4j here, I just want most of this to get
05: * compiled out.
06: * @version $Revision: 1.8 $
07: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
08: */
09: public final class Log {
10:
11: public static final boolean DEBUG = false;
12: public static final boolean INFO = true;
13: public static final boolean MESSAGE = true;
14: public static final boolean WARNING = true;
15: public static final int DEBUG_LEVEL = 0;
16: public static final int INFO_LEVEL = 1;
17: public static final int MESSAGE_LEVEL = 2;
18: public static final int WARNING_LEVEL = 3;
19: public static final int ERROR_LEVEL = 4;
20: public static final String[] LEVELS = { "DEBUG", "INFO", "MESSAGE",
21: "WARN", "ERROR" };
22: public static final long START = System.currentTimeMillis();
23: private final Class klass;
24:
25: public Log(Class klass) {
26: this .klass = klass;
27: }
28:
29: public final void debug(Object object) {
30:
31: if (DEBUG) {
32: log(DEBUG_LEVEL, object);
33: }
34: }
35:
36: public final void info(Object object) {
37:
38: if (INFO) {
39: log(INFO_LEVEL, object);
40: }
41: }
42:
43: public final void warn(Object object) {
44:
45: if (WARNING) {
46: log(WARNING_LEVEL, object);
47: }
48: }
49:
50: public final void message(Object object) {
51:
52: if (MESSAGE) {
53: log(MESSAGE_LEVEL, object);
54: }
55: }
56:
57: public final void error(Object object, Throwable throwable) {
58: log(ERROR_LEVEL, object);
59: throwable.printStackTrace(System.out);
60: }
61:
62: private void log(int level, Object object) {
63:
64: StringBuffer sb = new StringBuffer(30);
65:
66: sb.append(LEVELS[level]);
67: sb.append(" ");
68: sb.append(System.currentTimeMillis() - START);
69: sb.append(" ");
70: sb.append(klass.getName());
71: sb.append(" - ");
72: sb.append(object);
73: System.out.println(sb.toString());
74: }
75: }
|