01: /**
02: * Library name : Primrose - A Java Database Connection Pool.
03: * Published by Ben Keeping, http://primrose.org.uk .
04: * Copyright (C) 2004 Ben Keeping, primrose.org.uk
05: * Email: Use "Contact Us Form" on website
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */package uk.org.primrose;
21:
22: import java.io.*;
23: import java.util.*;
24:
25: /**
26: * Debug Logging class for the pools (straight to stdout).
27: */
28: public class DebugLogger {
29: private static boolean enabled = false;
30:
31: static {
32: try {
33: Process p = null;
34: try {
35: p = Runtime.getRuntime().exec("env");
36: } catch (Exception e) {
37: p = Runtime.getRuntime().exec(
38: "cmd /c set PRIMROSE_DEBUG");
39: }
40:
41: if (p != null) {
42: p.waitFor();
43: BufferedReader br = new BufferedReader(
44: new InputStreamReader(p.getInputStream()));
45: String line;
46: while ((line = br.readLine()) != null) {
47: if (line.toUpperCase().indexOf(
48: "PRIMROSE_DEBUG=TRUE") > -1) {
49: DebugLogger.setEnabled(true);
50: break;
51: }
52: }
53: }
54: } catch (Exception e) {
55: e.printStackTrace();
56: }
57: }
58:
59: public static boolean getEnabled() {
60: return enabled;
61: }
62:
63: public static void setEnabled(boolean bEnabled) {
64: enabled = bEnabled;
65: }
66:
67: /**
68: * Print a stack trace of the exception to stdout
69: */
70: public static void printStackTrace(Throwable t) {
71: if (!enabled)
72: return;
73: t.printStackTrace(System.out);
74: }
75:
76: /**
77: * Print to stdout a debug message
78: */
79: public static void log(String message) {
80: if (!enabled)
81: return;
82:
83: Calendar now = Calendar.getInstance();
84: String nowString = now.get(Calendar.DAY_OF_MONTH) + "/"
85: + (now.get(Calendar.MONTH) + 1) + "/"
86: + now.get(Calendar.YEAR) + " "
87: + now.get(Calendar.HOUR_OF_DAY) + ":"
88: + now.get(Calendar.MINUTE) + ":"
89: + now.get(Calendar.SECOND);
90:
91: message = nowString + " : PRIMROSE_DBG : " + message;
92: System.out.println(message);
93: }
94: }
|