Search in sources :

Example 51 with StreamHandler

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);
                    }
                }
            };
        }
    };
}
Also used : StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) StreamHandler(java.util.logging.StreamHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) Logger(java.util.logging.Logger)

Aggregations

StreamHandler (java.util.logging.StreamHandler)51 ByteArrayOutputStream (java.io.ByteArrayOutputStream)28 LogRecord (java.util.logging.LogRecord)17 SimpleFormatter (java.util.logging.SimpleFormatter)16 Logger (java.util.logging.Logger)12 Properties (java.util.Properties)7 MockResponse (com.google.mockwebserver.MockResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 Formatter (java.util.logging.Formatter)3 Handler (java.util.logging.Handler)3 PrintStream (java.io.PrintStream)2 CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)2 Before (org.junit.Before)2 Test (org.junit.Test)2 CommandRunner (com.google.copybara.util.CommandRunner)1 HighTemporalResolutionFormatter (com.ms.silverking.log.HighTemporalResolutionFormatter)1 XMLEncoder (java.beans.XMLEncoder)1 File (java.io.File)1