KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > message > Trace


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.message;
6
7
8 /**
9  * @author Thomas
10  */

11
12 public class Trace {
13     
14     // currently called trace because log mean something else
15
// TODO trace: java code generation does not always work
16

17     private TraceSystem traceSystem;
18     private String JavaDoc module;
19     private String JavaDoc lineSeparator;
20     
21     public static final String JavaDoc LOCK = "lock";
22     public static final String JavaDoc SETTING = "setting";
23     public static final String JavaDoc COMMAND = "command";
24     public static final String JavaDoc INDEX = "index";
25     public static final String JavaDoc SEQUENCE = "sequence";
26     public static final String JavaDoc CONSTRAINT = "constraint";
27     public static final String JavaDoc USER = "user";
28     public static final String JavaDoc TRIGGER = "trigger";
29     public static final String JavaDoc FUNCTION = "function";
30     public static final String JavaDoc JDBC = "jdbc";
31     public static final String JavaDoc FILE_LOCK = "fileLock";
32     public static final String JavaDoc TABLE = "table";
33     public static final String JavaDoc LOG = "log";
34     public static final String JavaDoc SCHEMA = "schema";
35     public static final String JavaDoc DATABASE = "database";
36     public static final String JavaDoc SESSION = "session";
37     
38     public Trace(TraceSystem traceSystem, String JavaDoc module) {
39         this.traceSystem = traceSystem;
40         this.module = module;
41         this.lineSeparator = System.getProperty("line.separator");
42     }
43     
44     public boolean info() {
45         return traceSystem.isEnabled(TraceSystem.INFO);
46     }
47     
48     public boolean debug() {
49         return traceSystem.isEnabled(TraceSystem.DEBUG);
50     }
51     
52     public void error(String JavaDoc s) {
53         traceSystem.write(TraceSystem.ERROR, module, s, null);
54     }
55
56     public void error(String JavaDoc s, Throwable JavaDoc t) {
57         traceSystem.write(TraceSystem.ERROR, module, s, t);
58     }
59     
60     public void info(String JavaDoc s) {
61         traceSystem.write(TraceSystem.INFO, module, s, null);
62     }
63
64     public void debugCode(String JavaDoc java) {
65         traceSystem.write(TraceSystem.DEBUG, module, lineSeparator + "/**/" + java, null);
66     }
67     
68     public void infoCode(String JavaDoc java) {
69         traceSystem.write(TraceSystem.INFO, module, lineSeparator + "/**/" + java, null);
70     }
71
72     public void infoSQL(String JavaDoc sql) {
73         sql = replaceNewline(sql);
74         
75         
76         if(sql.startsWith("/*")) {
77             sql = sql.substring(sql.indexOf("*/") + 2).trim();
78         }
79         traceSystem.write(TraceSystem.INFO, module, lineSeparator + "/*SQL*/" + sql, null);
80     }
81     
82     private String JavaDoc replaceNewline(String JavaDoc s) {
83         if(s.indexOf('\r') < 0 && s.indexOf('\n') < 0) {
84             return s;
85         }
86         StringBuffer JavaDoc buff = new StringBuffer JavaDoc(s.length());
87         for(int i=0; i<s.length(); i++) {
88             char ch = s.charAt(i);
89             if(ch == '\r' || ch == '\n') {
90                 ch = ' ';
91             }
92             buff.append(ch);
93         }
94         return buff.toString();
95     }
96
97     public void debug(String JavaDoc s) {
98         traceSystem.write(TraceSystem.DEBUG, module, s, null);
99     }
100
101     public void debug(String JavaDoc s, Throwable JavaDoc t) {
102         traceSystem.write(TraceSystem.DEBUG, module, s, t);
103     }
104     
105 }
106
Popular Tags