use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testPublish_EmptyMsg.
/*
* Test publish(), a log record with empty msg, having output stream
*/
public void testPublish_EmptyMsg() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
LogRecord r = new LogRecord(Level.INFO, "");
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head", this.errSubstituteStream.toString());
}
use of java.util.logging.ConsoleHandler in project heron by twitter.
the class LoggingHelper method loggerInit.
/**
* Init java util logging
*
* @param level the Level of message to log
* @param isRedirectStdOutErr whether we redirect std out&err
* @param format the format to log
*/
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
// Set the java util logging format
setLoggingFormat(format);
// Configure the root logger and its handlers so that all the
// derived loggers will inherit the properties
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
handler.setLevel(level);
}
rootLogger.setLevel(level);
if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
// zookeeper logging scares me. if people want this, we can patch to config-drive this
Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
}
if (isRedirectStdOutErr) {
// System.err to Logger, it results in an infinite loop.
for (Handler handler : rootLogger.getHandlers()) {
if (handler instanceof ConsoleHandler) {
rootLogger.removeHandler(handler);
}
}
// now rebind stdout/stderr to logger
Logger logger;
LoggingOutputStream los;
logger = Logger.getLogger("stdout");
los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT);
System.setOut(new PrintStream(los, true));
logger = Logger.getLogger("stderr");
los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
System.setErr(new PrintStream(los, true));
}
}
use of java.util.logging.ConsoleHandler in project commons by twitter.
the class RootLogConfigTest method setUp.
@Before
public void setUp() {
// Intercept stderr (this must be done first).
fakeErrorLog = new ByteArrayOutputStream();
errPrintStream = new PrintStream(fakeErrorLog);
System.setErr(errPrintStream);
// Create other members
consoleHandler = new ConsoleHandler();
fakeFileLog = new FakeHandler();
// Emulate default setup (just a console handler), but avoiding the use
// of the global root logger so not to get a flaky test due to background threads.
fakeRootLogger = Logger.getLogger("FakeRoot-" + UUID.randomUUID().toString());
fakeRootLogger.setUseParentHandlers(false);
for (Handler h : fakeRootLogger.getHandlers()) {
fakeRootLogger.removeHandler(h);
}
fakeRootLogger.addHandler(consoleHandler);
testLogger = Logger.getLogger(RootLogConfigTest.class.getName());
testLogger.setUseParentHandlers(true);
testLogger.setParent(fakeRootLogger);
setFakeRootForLogger(ClassA.logger);
setFakeRootForLogger(ClassB.logger);
resetLogs();
}
use of java.util.logging.ConsoleHandler in project reversehttp by tonyg.
the class EndpointService 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 CoreNLP by stanfordnlp.
the class JavaUtilLoggingAdaptor method adapt.
public static void adapt() {
// get the top Logger:
Logger topLogger = Logger.getLogger("");
Handler oldConsoleHandler = null;
// TODO confirm that this will always give us all handlers (i.e. do we need to loop over all Loggers in java.util.LogManager and do this for each one?)
for (Handler handler : topLogger.getHandlers()) {
if (handler instanceof ConsoleHandler && !(handler instanceof RedwoodHandler)) {
// found the console handler
oldConsoleHandler = handler;
break;
}
}
if (oldConsoleHandler != null) {
// it's safe to call this after it's been removed
topLogger.removeHandler(oldConsoleHandler);
}
if (!addedRedwoodHandler) {
Handler redwoodHandler = new JavaUtilLoggingAdaptor.RedwoodHandler();
topLogger.addHandler(redwoodHandler);
addedRedwoodHandler = true;
}
}
Aggregations