Search in sources :

Example 26 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project j2objc by google.

the class StreamHandlerTest method testIsLoggable_NoFilter.

/*
	 * Test isLoggable(), use no filter, having output stream
	 */
public void testIsLoggable_NoFilter() {
    StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter());
    LogRecord r = new LogRecord(Level.INFO, null);
    assertTrue(h.isLoggable(r));
    h.setLevel(Level.WARNING);
    assertFalse(h.isLoggable(r));
    h.setLevel(Level.CONFIG);
    assertTrue(h.isLoggable(r));
    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    assertFalse(h.isLoggable(r));
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 27 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project malmo by Microsoft.

the class TCPSocketHelper method setLogging.

static void setLogging(boolean log) {
    logging = log;
    if (log == true && filehandler == null) {
        try {
            filehandler = new FileHandler("TCPLog.txt");
            filehandler.setFormatter(new SimpleFormatter());
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        logger.addHandler(filehandler);
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Example 28 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project jreversepro by akkumar.

the class CustomLoggerFactory method createLogger.

public static Logger createLogger() {
    final Logger logger = Logger.getLogger("JReversePro");
    final SimpleFormatter formatter = new SimpleFormatter();
    final StreamHandler handler = new StreamHandler(System.out, formatter);
    logger.addHandler(handler);
    logger.setLevel(Level.FINER);
    return logger;
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) StreamHandler(java.util.logging.StreamHandler) Logger(java.util.logging.Logger)

Example 29 with SimpleFormatter

use of java.util.logging.SimpleFormatter 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);
                    }
                }
            };
        }
    };
}
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)

Example 30 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project okhttp by square.

the class Main method enableHttp2FrameLogging.

private static void enableHttp2FrameLogging() {
    frameLogger = Logger.getLogger(Http2.class.getName());
    frameLogger.setLevel(Level.FINE);
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINE);
    handler.setFormatter(new SimpleFormatter() {

        @Override
        public String format(LogRecord record) {
            return Util.format("%s%n", record.getMessage());
        }
    });
    frameLogger.addHandler(handler);
}
Also used : LogRecord(java.util.logging.LogRecord) SimpleFormatter(java.util.logging.SimpleFormatter) ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

SimpleFormatter (java.util.logging.SimpleFormatter)40 StreamHandler (java.util.logging.StreamHandler)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 Logger (java.util.logging.Logger)13 FileHandler (java.util.logging.FileHandler)9 LogRecord (java.util.logging.LogRecord)8 Handler (java.util.logging.Handler)7 MockResponse (com.google.mockwebserver.MockResponse)6 IOException (java.io.IOException)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 ConsoleHandler (java.util.logging.ConsoleHandler)4 Level (java.util.logging.Level)3 Test (org.junit.Test)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 File (java.io.File)2 Properties (java.util.Properties)2 MemoryHandler (java.util.logging.MemoryHandler)2 MockResponse (okhttp3.mockwebserver.MockResponse)2