File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\message\TraceWriterAdapter.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.message;
8
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 /**
13 * This adapter sends log output to SLF4J. SLF4J supports multiple
14 * implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), JDK
15 * 1.4 logging, x4juli, and Simple Log. To use SLF4J, you need to add the
16 * required jar files to the classpath, and set the trace level to 4 when opening
17 * a database:
18 *
19 * <pre>
20 * jdbc:h2:&tilde;/test;TRACE_LEVEL_FILE=4
21 * </pre>
22 *
23 * The logger name is 'h2database'.
24 */
25 public class TraceWriterAdapter implements TraceWriter {
26
27 private String name;
28 private final Logger logger = LoggerFactory.getLogger("h2database");
29
30 public void setName(String name) {
31 this.name = name;
32 }
33
34 public boolean isEnabled(int level) {
35 switch (level) {
36 case TraceSystem.DEBUG:
37 return logger.isDebugEnabled();
38 case TraceSystem.INFO:
39 return logger.isInfoEnabled();
40 case TraceSystem.ERROR:
41 return logger.isErrorEnabled();
42 default:
43 return false;
44 }
45 }
46
47 public void write(int level, String module, String s, Throwable t) {
48 if (isEnabled(level)) {
49 if (name != null) {
50 s = name + ":" + module + " " + s;
51 } else {
52 s = module + " " + s;
53 }
54 switch (level) {
55 case TraceSystem.DEBUG:
56 logger.debug(s, t);
57 break;
58 case TraceSystem.INFO:
59 logger.info(s, t);
60 break;
61 case TraceSystem.ERROR:
62 logger.error(s, t);
63 break;
64 default:
65 }
66 }
67 }
68
69 }
70