- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.java
More file actions
Latest commit
54 lines (46 loc) · 1.59 KB
/
Copy pathDebug.java
File metadata and controls
54 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
packagesimpledb;
/**
* Debug is a utility class that wraps println statements and allows
* more or less command line output to be turned on.
* <p>
* Change the value of the DEBUG_LEVEL constant using a system property:
* simpledb.Debug. For example, on the command line, use -Dsimpledb.Debug=x,
* or simply -Dsimpledb.Debug to enable it at level 0.
* The log(level, message, ...) method will print to standard output if the
* level number is less than or equal to the currently set DEBUG_LEVEL.
*/
publicclassDebug {
privatestaticfinalintDEBUG_LEVEL;
static {
Stringdebug = System.getProperty("simpledb.Debug");
if (debug == null) {
// No system property = disabled
DEBUG_LEVEL = -1;
} elseif (debug == "") {
// Empty property = level 0
DEBUG_LEVEL = 0;
} else {
DEBUG_LEVEL = Integer.parseInt(debug);
}
}
privatestaticfinalintDEFAULT_LEVEL = 0;
/** Log message if the log level >= level. Uses printf. */
publicstaticvoidlog(intlevel, Stringmessage, Object... args) {
if (isEnabled(level)) {
System.out.printf(message, args);
System.out.println();
}
}
/** @return true if level is being logged. */
publicstaticbooleanisEnabled(intlevel) {
returnlevel <= DEBUG_LEVEL;
}
/** @return true if the default level is being logged. */
publicstaticbooleanisEnabled() {
returnisEnabled(DEFAULT_LEVEL);
}
/** Logs message at the default log level. */
publicstaticvoidlog(Stringmessage, Object... args) {
log(DEFAULT_LEVEL, message, args);
}
}