use of java.util.logging.StreamHandler in project neo4j by neo4j.
the class SuppressOutput method java_util_logging.
private 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) {
for (Handler handler : handlers) {
logger.addHandler(handler);
}
logger.setLevel(level);
if (replacement != null) {
logger.removeHandler(replacement);
}
}
};
}
};
}
Aggregations