1 5 package org.h2.message; 6 7 8 11 12 public class Trace { 13 14 17 private TraceSystem traceSystem; 18 private String module; 19 private String lineSeparator; 20 21 public static final String LOCK = "lock"; 22 public static final String SETTING = "setting"; 23 public static final String COMMAND = "command"; 24 public static final String INDEX = "index"; 25 public static final String SEQUENCE = "sequence"; 26 public static final String CONSTRAINT = "constraint"; 27 public static final String USER = "user"; 28 public static final String TRIGGER = "trigger"; 29 public static final String FUNCTION = "function"; 30 public static final String JDBC = "jdbc"; 31 public static final String FILE_LOCK = "fileLock"; 32 public static final String TABLE = "table"; 33 public static final String LOG = "log"; 34 public static final String SCHEMA = "schema"; 35 public static final String DATABASE = "database"; 36 public static final String SESSION = "session"; 37 38 public Trace(TraceSystem traceSystem, String 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 s) { 53 traceSystem.write(TraceSystem.ERROR, module, s, null); 54 } 55 56 public void error(String s, Throwable t) { 57 traceSystem.write(TraceSystem.ERROR, module, s, t); 58 } 59 60 public void info(String s) { 61 traceSystem.write(TraceSystem.INFO, module, s, null); 62 } 63 64 public void debugCode(String java) { 65 traceSystem.write(TraceSystem.DEBUG, module, lineSeparator + "/**/" + java, null); 66 } 67 68 public void infoCode(String java) { 69 traceSystem.write(TraceSystem.INFO, module, lineSeparator + "/**/" + java, null); 70 } 71 72 public void infoSQL(String 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 replaceNewline(String s) { 83 if(s.indexOf('\r') < 0 && s.indexOf('\n') < 0) { 84 return s; 85 } 86 StringBuffer buff = new StringBuffer (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 s) { 98 traceSystem.write(TraceSystem.DEBUG, module, s, null); 99 } 100 101 public void debug(String s, Throwable t) { 102 traceSystem.write(TraceSystem.DEBUG, module, s, t); 103 } 104 105 } 106 | Popular Tags |