KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > smartlib > pool > core > Debugger


1 /*
2  * @(#) Debugger 1.0 02/08/01
3  */

4
5
6
7 package org.smartlib.pool.core;
8
9 /**
10  * This class is used for debugging, rather just to have a centalized
11  * gateway to standard output and few more things.
12  *
13  * @author Sachin Shekar Shetty
14  * @version 1.0, 02/08/01
15  *
16  */

17
18 import java.io.*;
19
20 public class Debugger {
21
22     private final boolean DEBUG;
23     private static boolean STATICDEBUG = false;
24     private final String JavaDoc CLASSNAME;
25     private static PrintStream outStream;
26     private static PrintWriter out = null;
27
28
29     public Debugger(String JavaDoc fileName, String JavaDoc className) {
30
31         System.out.println("Disributed Debugger is initailizing ;) ....");
32         STATICDEBUG = true;
33         DEBUG = true;
34         CLASSNAME = className;
35         try {
36             outStream = new PrintStream(new FileOutputStream(
37                         fileName, true));
38             out = new PrintWriter(outStream, true);
39             out.println("");
40             out.println("*****Logger initialized at " + new java.util.Date JavaDoc()
41                     + " *****");
42             out.println("");
43             System.out.println("Enterprise Log file located at: " + fileName);
44         }
45         catch (Exception JavaDoc exp) {
46             System.err.println("Could not open log file:" + fileName);
47             System.err.println("Exception: " + exp);
48             System.err.println("No Messages will be logged");
49             STATICDEBUG = false;
50         }
51
52     }
53     
54     public Debugger(String JavaDoc className ,boolean DEBUG) {
55
56         this.DEBUG = DEBUG;
57         CLASSNAME = className;
58
59     }
60
61     
62     public void writeException(Exception JavaDoc exp) {
63
64         if (DEBUG && STATICDEBUG) {
65             out.println("<message class='" + CLASSNAME + "' time-stamp='"
66                     + new java.util.Date JavaDoc() + "'>");
67             out.println("<exception>" + exp + "</exception>");
68             out.println("<stack-trace>");
69             exp.printStackTrace(outStream);
70             out.println("</stack-trace>");
71             out.println("</message>");
72             outStream.flush();
73
74         }
75
76     }
77
78     public void print(String JavaDoc msg) {
79         
80         if (DEBUG && STATICDEBUG) {
81             out.println("<message class='" + CLASSNAME + "' time-stamp='"
82                     + new java.util.Date JavaDoc() + "'>");
83             out.println(msg);
84             out.println("</message>");
85             out.flush();
86         }
87
88     }
89
90
91
92     void waitHere() {
93
94         try {
95             System.in.read();
96         }
97         catch (IOException ie) {
98             System.err.println("DEBUGGER:Failed while waiting for input " + ie);
99         }
100
101     }
102
103
104
105 }
106
107
108
109
Popular Tags