01: /*
02: * @(#) Debugger 1.0 02/08/01
03: */
04:
05: package org.smartlib.pool.core;
06:
07: /**
08: * This class is used for debugging, rather just to have a centalized
09: * gateway to standard output and few more things.
10: *
11: * @author Sachin Shekar Shetty
12: * @version 1.0, 02/08/01
13: *
14: */
15:
16: import java.io.*;
17:
18: public class Debugger {
19:
20: private final boolean DEBUG;
21: private static boolean STATICDEBUG = false;
22: private final String CLASSNAME;
23: private static PrintStream outStream;
24: private static PrintWriter out = null;
25:
26: public Debugger(String fileName, String className) {
27:
28: System.out
29: .println("Disributed Debugger is initailizing ;) ....");
30: STATICDEBUG = true;
31: DEBUG = true;
32: CLASSNAME = className;
33: try {
34: outStream = new PrintStream(new FileOutputStream(fileName,
35: true));
36: out = new PrintWriter(outStream, true);
37: out.println("");
38: out.println("*****Logger initialized at "
39: + new java.util.Date() + " *****");
40: out.println("");
41: System.out.println("Enterprise Log file located at: "
42: + fileName);
43: } catch (Exception exp) {
44: System.err.println("Could not open log file:" + fileName);
45: System.err.println("Exception: " + exp);
46: System.err.println("No Messages will be logged");
47: STATICDEBUG = false;
48: }
49:
50: }
51:
52: public Debugger(String className, boolean DEBUG) {
53:
54: this .DEBUG = DEBUG;
55: CLASSNAME = className;
56:
57: }
58:
59: public void writeException(Exception exp) {
60:
61: if (DEBUG && STATICDEBUG) {
62: out.println("<message class='" + CLASSNAME
63: + "' time-stamp='" + new java.util.Date() + "'>");
64: out.println("<exception>" + exp + "</exception>");
65: out.println("<stack-trace>");
66: exp.printStackTrace(outStream);
67: out.println("</stack-trace>");
68: out.println("</message>");
69: outStream.flush();
70:
71: }
72:
73: }
74:
75: public void print(String msg) {
76:
77: if (DEBUG && STATICDEBUG) {
78: out.println("<message class='" + CLASSNAME
79: + "' time-stamp='" + new java.util.Date() + "'>");
80: out.println(msg);
81: out.println("</message>");
82: out.flush();
83: }
84:
85: }
86:
87: void waitHere() {
88:
89: try {
90: System.in.read();
91: } catch (IOException ie) {
92: System.err
93: .println("DEBUGGER:Failed while waiting for input "
94: + ie);
95: }
96:
97: }
98:
99: }
|