Skip to content

Commit e9d3023

Browse files
committed
SnapLoaderLogger: introduced generic logger API
1 parent 10a2b23 commit e9d3023

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package electrostatic.snaploader.util;
2+
3+
import java.util.logging.Level;
4+
import java.util.logging.Logger;
5+
6+
public final class SnapLoaderLogger {
7+
8+
/**
9+
* NativeBinaryLoader logger object.
10+
*/
11+
private static final Logger logger = Logger.getLogger("jSnapLoader");
12+
13+
/**
14+
* Flag for enable/disable logging.
15+
*/
16+
private static boolean loggingEnabled;
17+
18+
/**
19+
* Log data with a level and a throwable (optional).
20+
*
21+
* @param level the logger level
22+
* @param sourceMethod the source of this call
23+
* @param msg a string formatted message to display
24+
*/
25+
public static void log(Level level, String sourceClass, String sourceMethod, String msg) {
26+
if (!SnapLoaderLogger.isLoggingEnabled()) {
27+
return;
28+
}
29+
logger.logp(level, sourceClass, sourceMethod, msg);
30+
}
31+
32+
/**
33+
* Log data with a level and a throwable (optional).
34+
*
35+
* @param level the logger level
36+
* @param sourceMethod the source of this call
37+
* @param msg a string formatted message to display
38+
* @param throwable optional param for error messages
39+
*/
40+
public static void log(Level level, String sourceClass, String sourceMethod, String msg, Throwable throwable) {
41+
if (!SnapLoaderLogger.isLoggingEnabled()) {
42+
return;
43+
}
44+
logger.logp(level, sourceClass, sourceMethod, msg, throwable);
45+
}
46+
47+
/**
48+
* Enables the logging for this object, default value is false.
49+
*
50+
* @param loggingEnabled true to enable logging, false otherwise
51+
*/
52+
public static void setLoggingEnabled(boolean loggingEnabled) {
53+
SnapLoaderLogger.loggingEnabled = loggingEnabled;
54+
}
55+
56+
/**
57+
* Tests the logging flag, default value is false.
58+
*
59+
* @return true if the logging flag is enabled, false otherwise
60+
*/
61+
public static boolean isLoggingEnabled() {
62+
return SnapLoaderLogger.loggingEnabled;
63+
}
64+
}

0 commit comments

Comments
 (0)