Search in sources :

Example 26 with Logger

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

the class OldLogManagerTest method testGetLogger_nameSpace.

/*
     * test for method public Logger getLogger(String name)
     */
public void testGetLogger_nameSpace() throws Exception {
    // test name with space
    Logger foo = new MockLogger(FOO, null);
    Logger fooBeforeSpace = new MockLogger(FOO + " ", null);
    Logger fooAfterSpace = new MockLogger(" " + FOO, null);
    Logger fooWithBothSpace = new MockLogger(" " + FOO + " ", null);
    assertTrue(mockManager.addLogger(foo));
    assertTrue(mockManager.addLogger(fooBeforeSpace));
    assertTrue(mockManager.addLogger(fooAfterSpace));
    assertTrue(mockManager.addLogger(fooWithBothSpace));
    assertSame(foo, mockManager.getLogger(FOO));
    assertSame(fooBeforeSpace, mockManager.getLogger(FOO + " "));
    assertSame(fooAfterSpace, mockManager.getLogger(" " + FOO));
    assertSame(fooWithBothSpace, mockManager.getLogger(" " + FOO + " "));
}
Also used : Logger(java.util.logging.Logger)

Example 27 with Logger

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

the class OldLogManagerTest method testGetLogger_duplicateName.

/*
     * test for method public Logger getLogger(String name)
     */
public void testGetLogger_duplicateName() throws Exception {
    // test duplicate name
    // add logger with duplicate name has no effect
    mockManager.reset();
    Logger foo2 = new MockLogger(FOO, null);
    Logger foo3 = new MockLogger(FOO, null);
    mockManager.addLogger(foo2);
    assertSame(foo2, mockManager.getLogger(FOO));
    mockManager.addLogger(foo3);
    assertSame(foo2, mockManager.getLogger(FOO));
    Enumeration<String> enumar2 = mockManager.getLoggerNames();
    int i = 0;
    while (enumar2.hasMoreElements()) {
        enumar2.nextElement();
        i++;
    }
    assertEquals(1, i);
}
Also used : Logger(java.util.logging.Logger)

Example 28 with Logger

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

the class OldLogManagerTest method testGetLogger_hierarchy.

/*
     * test for method public Logger getLogger(String name)
     */
public void testGetLogger_hierarchy() throws Exception {
    // test hierarchy
    Logger foo = new MockLogger("testGetLogger_hierachy.foo", null);
    // but for non-mock LogManager, foo's parent should be root
    assertTrue(manager.addLogger(foo));
    assertSame(manager.getLogger(""), manager.getLogger("testGetLogger_hierachy.foo").getParent());
}
Also used : Logger(java.util.logging.Logger)

Example 29 with Logger

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

the class OldLoggerTest method testGetLogger_WithParent.

public void testGetLogger_WithParent() {
    assertNull(LogManager.getLogManager().getLogger("testGetLogger_WithParent_ParentLogger"));
    // get root of hierarchy
    Logger root = Logger.getLogger("");
    // create the parent logger
    Logger pLog = Logger.getLogger("testGetLogger_WithParent_ParentLogger", VALID_RESOURCE_BUNDLE);
    pLog.setLevel(Level.CONFIG);
    pLog.addHandler(new MockHandler());
    pLog.setFilter(new MockFilter());
    pLog.setUseParentHandlers(false);
    // check root parent
    assertEquals("testGetLogger_WithParent_ParentLogger", pLog.getName());
    assertSame(pLog.getParent(), root);
    // child part
    assertNull(LogManager.getLogManager().getLogger("testGetLogger_WithParent_ParentLogger.child"));
    // create the child logger
    Logger child = Logger.getLogger("testGetLogger_WithParent_ParentLogger.child");
    assertNull(child.getFilter());
    assertEquals(0, child.getHandlers().length);
    assertNull(child.getLevel());
    assertEquals("testGetLogger_WithParent_ParentLogger.child", child.getName());
    assertSame(child.getParent(), pLog);
    assertNull(child.getResourceBundle());
    assertNull(child.getResourceBundleName());
    assertTrue(child.getUseParentHandlers());
    // create not valid child
    Logger notChild = Logger.getLogger("testGetLogger_WithParent_ParentLogger1.child");
    assertNull(notChild.getFilter());
    assertEquals(0, notChild.getHandlers().length);
    assertNull(notChild.getLevel());
    assertEquals("testGetLogger_WithParent_ParentLogger1.child", notChild.getName());
    assertNotSame(notChild.getParent(), pLog);
    assertNull(notChild.getResourceBundle());
    assertNull(notChild.getResourceBundleName());
    assertTrue(notChild.getUseParentHandlers());
    // verify two level root.parent
    assertEquals("testGetLogger_WithParent_ParentLogger.child", child.getName());
    assertSame(child.getParent().getParent(), root);
    // create three level child
    Logger childOfChild = Logger.getLogger("testGetLogger_WithParent_ParentLogger.child.child");
    assertNull(childOfChild.getFilter());
    assertEquals(0, childOfChild.getHandlers().length);
    assertSame(child.getParent().getParent(), root);
    assertNull(childOfChild.getLevel());
    assertEquals("testGetLogger_WithParent_ParentLogger.child.child", childOfChild.getName());
    assertSame(childOfChild.getParent(), child);
    assertSame(childOfChild.getParent().getParent(), pLog);
    assertSame(childOfChild.getParent().getParent().getParent(), root);
    assertNull(childOfChild.getResourceBundle());
    assertNull(childOfChild.getResourceBundleName());
    assertTrue(childOfChild.getUseParentHandlers());
    // abnormal case : lookup to root parent in a hierarchy without a logger
    // parent created between
    assertEquals("testGetLogger_WithParent_ParentLogger1.child", notChild.getName());
    assertSame(child.getParent().getParent(), root);
    assertNotSame(child.getParent(), root);
    // abnormal cases
    assertNotSame(root.getParent(), root);
    Logger twoDot = Logger.getLogger("..");
    assertSame(twoDot.getParent(), root);
}
Also used : Logger(java.util.logging.Logger)

Example 30 with Logger

use of java.util.logging.Logger in project spring-boot by spring-projects.

the class JavaLoggingSystem method setLogLevel.

@Override
public void setLogLevel(String loggerName, LogLevel level) {
    Assert.notNull(level, "Level must not be null");
    if (loggerName == null || ROOT_LOGGER_NAME.equals(loggerName)) {
        loggerName = "";
    }
    Logger logger = Logger.getLogger(loggerName);
    if (logger != null) {
        logger.setLevel(LEVELS.convertSystemToNative(level));
    }
}
Also used : Logger(java.util.logging.Logger)

Aggregations

Logger (java.util.logging.Logger)362 LogRecord (java.util.logging.LogRecord)43 Test (org.junit.Test)41 Handler (java.util.logging.Handler)35 File (java.io.File)18 IOException (java.io.IOException)18 ConsoleHandler (java.util.logging.ConsoleHandler)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Level (java.util.logging.Level)11 LogManager (java.util.logging.LogManager)10 ArrayList (java.util.ArrayList)8 StreamHandler (java.util.logging.StreamHandler)8 ResourceBundle (java.util.ResourceBundle)7 MockResponse (com.google.mockwebserver.MockResponse)6 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 FileHandler (java.util.logging.FileHandler)5 TestLogHandler (com.google.common.testing.TestLogHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4