Hard-coded java.util.logging commons-logging implementation.
| 26 | * Hard-coded java.util.logging commons-logging implementation. |
| 27 | */ |
| 28 | class DirectJDKLog implements Log { |
| 29 | // no reason to hide this - but good reasons to not hide |
| 30 | public final Logger logger; |
| 31 | |
| 32 | // Alternate config reader and console format |
| 33 | private static final String SIMPLE_FMT = "java.util.logging.SimpleFormatter"; |
| 34 | private static final String FORMATTER = "org.apache.juli.formatter"; |
| 35 | |
| 36 | static { |
| 37 | if (System.getProperty("java.util.logging.config.class") == null && |
| 38 | System.getProperty("java.util.logging.config.file") == null) { |
| 39 | // default configuration - it sucks. Let's override at least the |
| 40 | // formatter for the console |
| 41 | try { |
| 42 | Formatter fmt = (Formatter) Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).getConstructor() |
| 43 | .newInstance(); |
| 44 | // it is also possible that the user modified jre/lib/logging.properties - |
| 45 | // but that's really stupid in most cases |
| 46 | Logger root = Logger.getLogger(""); |
| 47 | for (Handler handler : root.getHandlers()) { |
| 48 | // I only care about console - that's what's used in default config anyway |
| 49 | if (handler instanceof ConsoleHandler) { |
| 50 | handler.setFormatter(fmt); |
| 51 | } |
| 52 | } |
| 53 | } catch (Throwable t) { |
| 54 | // maybe it wasn't included - the ugly default will be used. |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | DirectJDKLog(String name) { |
| 61 | logger = Logger.getLogger(name); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public final boolean isErrorEnabled() { |
| 66 | return logger.isLoggable(Level.SEVERE); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public final boolean isWarnEnabled() { |
| 71 | return logger.isLoggable(Level.WARNING); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public final boolean isInfoEnabled() { |
| 76 | return logger.isLoggable(Level.INFO); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public final boolean isDebugEnabled() { |
| 81 | return logger.isLoggable(Level.FINE); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public final boolean isFatalEnabled() { |
nothing calls this directly
no test coverage detected