use of java.util.logging.ConsoleHandler in project syncany by syncany.
the class CommandLineClient method initLogHandlers.
private void initLogHandlers(OptionSet options, OptionSpec<String> optionLog, OptionSpec<Void> optionLogPrint, OptionSpec<Void> optionDebug) throws SecurityException, IOException {
// --log=<file>
String logFilePattern = null;
if (options.has(optionLog)) {
if (!"-".equals(options.valueOf(optionLog))) {
logFilePattern = options.valueOf(optionLog);
}
} else if (config != null && config.getLogDir().exists()) {
logFilePattern = config.getLogDir() + File.separator + LOG_FILE_PATTERN;
} else {
logFilePattern = UserConfig.getUserLogDir() + File.separator + LOG_FILE_PATTERN;
}
if (logFilePattern != null) {
Handler fileLogHandler = new FileHandler(logFilePattern, LOG_FILE_LIMIT, LOG_FILE_COUNT, true);
fileLogHandler.setFormatter(new LogFormatter());
Logging.addGlobalHandler(fileLogHandler);
}
// --debug, add console handler
if (options.has(optionDebug) || options.has(optionLogPrint) || (options.has(optionLog) && "-".equals(options.valueOf(optionLog)))) {
Handler consoleLogHandler = new ConsoleHandler();
consoleLogHandler.setFormatter(new LogFormatter());
Logging.addGlobalHandler(consoleLogHandler);
}
}
use of java.util.logging.ConsoleHandler in project commons by twitter.
the class RootLogConfig method setConsoleHandler.
private static void setConsoleHandler(Logger logger, boolean removeOtherHandlers) {
Handler consoleHandler = null;
for (Handler h : logger.getHandlers()) {
if (h instanceof ConsoleHandler) {
consoleHandler = h;
} else if (removeOtherHandlers) {
logger.removeHandler(h);
}
}
if (consoleHandler == null) {
consoleHandler = new ConsoleHandler();
logger.addHandler(new ConsoleHandler());
}
consoleHandler.setLevel(Level.ALL);
consoleHandler.setFilter(null);
}
use of java.util.logging.ConsoleHandler in project reversehttp by tonyg.
the class TestNormalHttpService method configureLogging.
private static void configureLogging() {
ConsoleHandler handler = new ConsoleHandler();
Logger root = Logger.getLogger("");
root.addHandler(handler);
handler.setLevel(Level.FINER);
root.setLevel(Level.FINER);
}
use of java.util.logging.ConsoleHandler in project reversehttp by tonyg.
the class TestReverseHttpService method configureLogging.
private static void configureLogging() {
ConsoleHandler handler = new ConsoleHandler();
Logger root = Logger.getLogger("");
root.addHandler(handler);
// handler.setLevel(Level.FINER);
// root.setLevel(Level.FINER);
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class LogManagerTest method testReset.
public void testReset() throws SecurityException, IOException {
// mock LogManager
mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertNotNull(mockManager.getProperty("handlers"));
Logger foo = new MockLogger(FOO, null);
assertNull(foo.getLevel());
assertEquals(0, foo.getHandlers().length);
foo.setLevel(Level.ALL);
foo.addHandler(new ConsoleHandler());
assertTrue(mockManager.addLogger(foo));
assertEquals(Level.WARNING, foo.getLevel());
assertEquals(2, foo.getHandlers().length);
// reset
mockManager.reset();
// properties is cleared
assertNull(mockManager.getProperty("handlers"));
// level is null
assertNull(foo.getLevel());
// handlers are all closed
assertEquals(0, foo.getHandlers().length);
// for root logger
manager.reset();
assertNull(manager.getProperty("handlers"));
Logger root = manager.getLogger("");
// level reset to info
assertEquals(Level.INFO, root.getLevel());
// also close root's handler
assertEquals(0, root.getHandlers().length);
}
Aggregations