use of java.util.logging.Handler in project Towny by ElgarL.
the class TownyLogger method CloseDownLogger.
public static void CloseDownLogger(Logger logger) {
for (Handler fh : logger.getHandlers()) {
logger.removeHandler(fh);
fh.close();
}
}
use of java.util.logging.Handler 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;
}
}
use of java.util.logging.Handler in project CoreNLP by stanfordnlp.
the class MachineReading method setConsoleLevel.
public static void setConsoleLevel(Level level) {
// get the top Logger:
Logger topLogger = java.util.logging.Logger.getLogger("");
// Handler for console (reuse it if it already exists)
Handler consoleHandler = null;
// see if there is already a console handler
for (Handler handler : topLogger.getHandlers()) {
if (handler instanceof ConsoleHandler) {
// found the console handler
consoleHandler = handler;
break;
}
}
if (consoleHandler == null) {
// there was no console handler found, create a new one
consoleHandler = new ConsoleHandler();
topLogger.addHandler(consoleHandler);
}
// set the console handler level:
consoleHandler.setLevel(level);
consoleHandler.setFormatter(new SimpleFormatter());
}
use of java.util.logging.Handler in project neo4j by neo4j.
the class SuppressOutput method java_util_logging.
public static Suppressible java_util_logging(final ByteArrayOutputStream redirectTo, Level level) {
final Handler replacement = redirectTo == null ? null : new StreamHandler(redirectTo, new SimpleFormatter());
if (replacement != null && level != null) {
replacement.setLevel(level);
}
return new Suppressible() {
@Override
public Voice suppress() {
final Logger logger = LogManager.getLogManager().getLogger("");
final Level level = logger.getLevel();
final Handler[] handlers = logger.getHandlers();
for (Handler handler : handlers) {
logger.removeHandler(handler);
}
if (replacement != null) {
logger.addHandler(replacement);
logger.setLevel(Level.ALL);
}
return new Voice(this, redirectTo) {
@Override
void restore(boolean failure) throws IOException {
for (Handler handler : handlers) {
logger.addHandler(handler);
}
logger.setLevel(level);
if (replacement != null) {
logger.removeHandler(replacement);
}
}
};
}
};
}
use of java.util.logging.Handler in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method bridgeHandlerInstalled.
private boolean bridgeHandlerInstalled() {
Logger rootLogger = LogManager.getLogManager().getLogger("");
Handler[] handlers = rootLogger.getHandlers();
for (Handler handler : handlers) {
if (handler instanceof SLF4JBridgeHandler) {
return true;
}
}
return false;
}
Aggregations