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 + " "));
}
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);
}
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());
}
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);
}
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));
}
}
Aggregations