33 */ |
33 */ |
34 |
34 |
35 public final class Logger { |
35 public final class Logger { |
36 |
36 |
37 private final static int MAX_SIZE = 10000; |
37 private final static int MAX_SIZE = 10000; |
|
38 static { |
|
39 // This will try to initialize the JVM logging system |
|
40 JVMSupport.tryToInitializeJVM(); |
|
41 } |
|
42 |
38 |
43 |
39 public static void log(LogTag logTag, LogLevel logLevel, String message) { |
44 public static void log(LogTag logTag, LogLevel logLevel, String message) { |
40 if (logTag.shouldLog(logLevel.level)) { |
45 if (shouldLog(logTag, logLevel)) { |
41 logInternal(logTag, logLevel, message); |
46 logInternal(logTag, logLevel, message); |
42 } |
47 } |
43 } |
48 } |
44 |
49 |
45 public static void log(LogTag logTag, LogLevel logLevel, Supplier<String> messageSupplier) { |
50 public static void log(LogTag logTag, LogLevel logLevel, Supplier<String> messageSupplier) { |
46 if (logTag.shouldLog(logLevel.level)) { |
51 if (shouldLog(logTag, logLevel)) { |
47 logInternal(logTag, logLevel, messageSupplier.get()); |
52 logInternal(logTag, logLevel, messageSupplier.get()); |
48 } |
53 } |
49 } |
54 } |
50 |
55 |
51 private static void logInternal(LogTag logTag, LogLevel logLevel, String message) { |
56 private static void logInternal(LogTag logTag, LogLevel logLevel, String message) { |
53 JVM.log(logTag.id, logLevel.level, message); |
58 JVM.log(logTag.id, logLevel.level, message); |
54 } else { |
59 } else { |
55 JVM.log(logTag.id, logLevel.level, message.substring(0, MAX_SIZE)); |
60 JVM.log(logTag.id, logLevel.level, message.substring(0, MAX_SIZE)); |
56 } |
61 } |
57 } |
62 } |
|
63 |
|
64 public static boolean shouldLog(LogTag tag, LogLevel level) { |
|
65 return level.level >= tag.tagSetLevel; |
|
66 } |
58 } |
67 } |