Search in sources :

Example 36 with StreamHandler

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

the class StreamHandlerTest method testPublish_EmptyMsg.

/*
	 * Test publish(), a log record with empty msg, having output stream
	 */
public void testPublish_EmptyMsg() {
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    LogRecord r = new LogRecord(Level.INFO, "");
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head", aos.toString());
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 37 with StreamHandler

use of java.util.logging.StreamHandler 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 38 with StreamHandler

use of java.util.logging.StreamHandler 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 39 with StreamHandler

use of java.util.logging.StreamHandler in project android_frameworks_base by AOSPA.

the class CookiesTest method testCookiesAreNotLogged.

/**
     * Test that we don't log potentially sensitive cookie values.
     * http://b/3095990
     */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();
        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 40 with StreamHandler

use of java.util.logging.StreamHandler in project robovm by robovm.

the class OldFormatterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    h = new StreamHandler();
}
Also used : StreamHandler(java.util.logging.StreamHandler)

Aggregations

StreamHandler (java.util.logging.StreamHandler)41 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 SimpleFormatter (java.util.logging.SimpleFormatter)15 LogRecord (java.util.logging.LogRecord)14 Logger (java.util.logging.Logger)8 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 Handler (java.util.logging.Handler)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Level (java.util.logging.Level)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 Before (org.junit.Before)1 Test (org.junit.Test)1