0
|
1
|
|
2 package com.trilead.ssh2.log;
|
|
3
|
|
4 import com.trilead.ssh2.DebugLogger;
|
|
5
|
|
6 /**
|
|
7 * Logger - a very simple logger, mainly used during development.
|
|
8 * Is not based on log4j (to reduce external dependencies).
|
|
9 * However, if needed, something like log4j could easily be
|
|
10 * hooked in.
|
|
11 * <p>
|
|
12 * For speed reasons, the static variables are not protected
|
|
13 * with semaphores. In other words, if you dynamicaly change the
|
|
14 * logging settings, then some threads may still use the old setting.
|
|
15 *
|
|
16 * @author Christian Plattner, plattner@trilead.com
|
|
17 * @version $Id: Logger.java,v 1.2 2008/03/03 07:01:36 cplattne Exp $
|
|
18 */
|
|
19
|
|
20 public class Logger {
|
|
21 public static boolean enabled = false;
|
|
22 public static DebugLogger logger = null;
|
|
23
|
|
24 private String className;
|
|
25
|
|
26 public final static Logger getLogger(Class x) {
|
|
27 return new Logger(x);
|
|
28 }
|
|
29
|
|
30 public Logger(Class x) {
|
|
31 this.className = x.getName();
|
|
32 }
|
|
33
|
|
34 public final boolean isEnabled() {
|
|
35 return enabled;
|
|
36 }
|
|
37
|
|
38 public final void log(int level, String message) {
|
|
39 if (!enabled)
|
|
40 return;
|
|
41
|
|
42 DebugLogger target = logger;
|
|
43
|
|
44 if (target == null)
|
|
45 return;
|
|
46
|
|
47 target.log(level, className, message);
|
|
48 }
|
|
49 }
|