Search in sources :

Example 41 with Logger

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

the class LoggerTest method testGetParent_NormalNamed.

/*
	 * Test getParent() for normal named loggers.
	 */
public void testGetParent_NormalNamed() {
    Logger log = Logger.getLogger("testGetParent_NormalNamed");
    assertSame(log.getParent(), Logger.getLogger(""));
    Logger child = Logger.getLogger("testGetParent_NormalNamed.child");
    assertSame(child.getParent(), log);
    Logger child2 = Logger.getLogger("testGetParent_NormalNamed.a.b.c");
    assertSame(child2.getParent(), log);
}
Also used : Logger(java.util.logging.Logger)

Example 42 with Logger

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

the class LoggerTest method testLogp_LevelStringStringStringObjects_NullMsgObj.

/*
	 * Test logp(Level, String, String, String, Object[]) with null message and
	 * object.
	 */
public void testLogp_LevelStringStringStringObjects_NullMsgObj() {
    Logger child = new MockLogger("childLogger", null);
    Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.addHandler(new MockHandler());
    child.setParent(parent);
    child.setLevel(Level.INFO);
    child.logp(Level.INFO, null, null, null, (Object[]) null);
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), child.getName());
    assertNull(r.getMessage());
    assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
    assertSame(r.getResourceBundle(), parent.getResourceBundle());
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.INFO);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger)

Example 43 with Logger

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

the class LoggerTest method testGetSetLevel_Null.

/*
	 * Test getLevel & setLevel with null value, having sufficient privilege.
	 */
public void testGetSetLevel_Null() {
    Logger log = Logger.getLogger("testGetSetLevel_Null");
    assertNull(log.getLevel());
    log.setLevel(null);
    assertNull(log.getLevel());
    log.setLevel(Level.CONFIG);
    log.setLevel(null);
    assertNull(log.getLevel());
}
Also used : Logger(java.util.logging.Logger)

Example 44 with Logger

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

the class LoggerTest method testGetLoggerWithRes_Normal.

// /*
// * Test getLogger(String), getting a logger with existing parent, using
// * abnormal names (containing '.').
// */
// public void testGetLogger_WithParentAbnormal() {
// Logger log = Logger.getLogger(".");
// assertSame(log.getParent(), Logger.getLogger(""));
// Logger log2 = Logger.getLogger("..");
// assertSame(log2.getParent(), Logger.getLogger(""));
// //TODO: a lot more can be tested
// }
/*
	 * Test getLogger(String, String), getting a logger with no parent.
	 */
public void testGetLoggerWithRes_Normal() throws Exception {
    // config the level
    Properties p = new Properties();
    p.put("testGetLoggerWithRes_Normal_ANewLogger.level", "ALL");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertNull(LogManager.getLogManager().getLogger("testGetLoggerWithRes_Normal_ANewLogger"));
    // create a new logger
    Logger log = Logger.getLogger("testGetLoggerWithRes_Normal_ANewLogger", VALID_RESOURCE_BUNDLE);
    // get an existing logger
    assertSame(log, Logger.getLogger("testGetLoggerWithRes_Normal_ANewLogger"));
    // check it has been registered
    assertSame(log, LogManager.getLogManager().getLogger("testGetLoggerWithRes_Normal_ANewLogger"));
    assertNull(log.getFilter());
    assertEquals(0, log.getHandlers().length);
    // check it's set to the preconfigured level
    assertSame(Level.ALL, log.getLevel());
    assertEquals("testGetLoggerWithRes_Normal_ANewLogger", log.getName());
    assertNull(log.getParent().getParent());
    assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY));
    assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
    assertTrue(log.getUseParentHandlers());
}
Also used : Properties(java.util.Properties) Logger(java.util.logging.Logger)

Example 45 with Logger

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

the class LoggerTest method testGetLogger_Normal.

/*
	 * Test getLogger(String), getting a logger with no parent.
	 */
public void testGetLogger_Normal() throws Exception {
    // config the level
    Properties p = new Properties();
    p.put("testGetLogger_Normal_ANewLogger.level", "ALL");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertNull(LogManager.getLogManager().getLogger("testGetLogger_Normal_ANewLogger"));
    // create a new logger
    Logger log = Logger.getLogger("testGetLogger_Normal_ANewLogger");
    // get an existing logger
    assertSame(log, Logger.getLogger("testGetLogger_Normal_ANewLogger"));
    // check it has been registered
    assertSame(log, LogManager.getLogManager().getLogger("testGetLogger_Normal_ANewLogger"));
    assertNull(log.getFilter());
    assertEquals(0, log.getHandlers().length);
    // check it's set to the preconfigured level
    assertSame(Level.ALL, log.getLevel());
    assertEquals("testGetLogger_Normal_ANewLogger", log.getName());
    assertNull(log.getParent().getParent());
    assertNull(log.getResourceBundle());
    assertNull(log.getResourceBundleName());
    assertTrue(log.getUseParentHandlers());
}
Also used : Properties(java.util.Properties) Logger(java.util.logging.Logger)

Aggregations

Logger (java.util.logging.Logger)499 Test (org.junit.Test)70 LogRecord (java.util.logging.LogRecord)60 ActionReport (org.glassfish.api.ActionReport)56 Handler (java.util.logging.Handler)52 IOException (java.io.IOException)37 File (java.io.File)36 Level (java.util.logging.Level)25 ArrayList (java.util.ArrayList)22 ConsoleHandler (java.util.logging.ConsoleHandler)19 Properties (java.util.Properties)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Config (com.sun.enterprise.config.serverbeans.Config)14 HashMap (java.util.HashMap)14 Map (java.util.Map)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ResourceBundle (java.util.ResourceBundle)11 LogManager (java.util.logging.LogManager)11 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10