Search in sources :

Example 46 with SimpleFormatter

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

the class MemoryHandlerTest method testMemoryHandlerInvalidProps.

public void testMemoryHandlerInvalidProps() throws IOException {
    // null target
    try {
        props.remove("java.util.logging.MemoryHandler.target");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        handler = new MemoryHandler();
        fail("should throw RuntimeException: target must be set");
    } catch (RuntimeException e) {
    }
    // invalid target
    try {
        props.put("java.util.logging.MemoryHandler.target", "badname");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        handler = new MemoryHandler();
        fail("should throw RuntimeException: target must be valid");
    } catch (RuntimeException e) {
    }
    // invalid formatter
    initProps();
    props.put("java.util.logging.MemoryHandler.formatter", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertTrue(handler.getFormatter() instanceof SimpleFormatter);
    // invalid level
    initProps();
    props.put("java.util.logging.MemoryHandler.level", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertEquals(handler.getLevel(), Level.ALL);
    // invalid pushlevel
    initProps();
    props.put("java.util.logging.MemoryHandler.push", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertEquals(handler.getPushLevel(), Level.SEVERE);
    // invalid filter
    initProps();
    props.put("java.util.logging.MemoryHandler.filter", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertNull(handler.getFilter());
    // invalid size
    initProps();
    props.put("java.util.logging.MemoryHandler.size", "-1");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    initProps();
    props.put("java.util.logging.MemoryHandler.size", "badsize");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) MemoryHandler(java.util.logging.MemoryHandler)

Example 47 with SimpleFormatter

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

the class MemoryHandlerTest method testMemoryHandlerDefaultValue.

public void testMemoryHandlerDefaultValue() throws SecurityException, IOException {
    props.clear();
    props.put("java.util.logging.MemoryHandler.target", baseClassName + "$MockHandler");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertNull(handler.getFilter());
    assertTrue(handler.getFormatter() instanceof SimpleFormatter);
    assertNull(handler.getEncoding());
    assertNotNull(handler.getErrorManager());
    assertEquals(handler.getLevel(), Level.ALL);
    assertEquals(handler.getPushLevel(), Level.SEVERE);
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) MemoryHandler(java.util.logging.MemoryHandler)

Example 48 with SimpleFormatter

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

the class StreamHandlerTest method testSetOutputStream_null.

/*
	 * Test setOutputStream() with null.
	 */
public void testSetOutputStream_null() {
    MockStreamHandler h = new MockStreamHandler(new ByteArrayOutputStream(), new SimpleFormatter());
    try {
        h.setOutputStream(null);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 49 with SimpleFormatter

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

the class StreamHandlerTest method testConstructor_NoParameter_InvalidProperties.

/*
	 * Test the constructor with no parameter, and invalid relevant log manager
	 * properties are set.
	 */
public void testConstructor_NoParameter_InvalidProperties() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.StreamHandler.level", INVALID_LEVEL);
    p.put("java.util.logging.StreamHandler.filter", className + "");
    p.put("java.util.logging.StreamHandler.formatter", className + "");
    p.put("java.util.logging.StreamHandler.encoding", "XXXX");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertEquals(INVALID_LEVEL, LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.level"));
    assertEquals("XXXX", LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.encoding"));
    StreamHandler h = new StreamHandler();
    assertSame(Level.INFO, h.getLevel());
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
    h.publish(new LogRecord(Level.SEVERE, "test"));
    assertTrue(CallVerificationStack.getInstance().empty());
    assertNull(h.getEncoding());
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) Properties(java.util.Properties)

Example 50 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)

Aggregations

SimpleFormatter (java.util.logging.SimpleFormatter)100 FileHandler (java.util.logging.FileHandler)59 Logger (java.util.logging.Logger)36 File (java.io.File)28 Handler (java.util.logging.Handler)23 IOException (java.io.IOException)17 StreamHandler (java.util.logging.StreamHandler)16 Properties (java.util.Properties)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 LogRecord (java.util.logging.LogRecord)13 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)13 Config (edu.neu.ccs.pyramid.configuration.Config)11 ConsoleHandler (java.util.logging.ConsoleHandler)10 Formatter (java.util.logging.Formatter)9 Test (org.junit.Test)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 Pair (edu.neu.ccs.pyramid.util.Pair)3