Search in sources :

Example 31 with LogRecord

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

the class LoggerTest method testLog_LevelStringThrowable_Normal.

/*
	 * Test log(Level, String, Throwable) with normal values.
	 */
public void testLog_LevelStringThrowable_Normal() {
    Throwable t = new Throwable();
    this.sharedLogger.setLevel(Level.INFO);
    this.sharedLogger.log(Level.INFO, "log(Level, String, Throwable) msg", t);
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), this.sharedLogger.getName());
    assertEquals(r.getMessage(), "log(Level, String, Throwable) msg");
    assertSame(r.getResourceBundleName(), this.sharedLogger.getResourceBundleName());
    assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.INFO);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), t);
    this.sharedLogger.log(Level.CONFIG, "log(Level, String, Throwable) msg", t);
    assertTrue(CallVerificationStack.getInstance().empty());
    this.sharedLogger.setLevel(Level.OFF);
    this.sharedLogger.log(Level.OFF, "log(Level, String, Throwable) msg", t);
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 32 with LogRecord

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

the class LoggerTest method testLog_ParentNotInformed.

/*
	 * Test that the parent's handler is notified for a new log record when
	 * getUseParentHandlers() is false.
	 */
public void testLog_ParentNotInformed() {
    Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE);
    Logger parent = new MockParentLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.setParent(parent);
    child.setLevel(Level.INFO);
    parent.setLevel(Level.INFO);
    parent.addHandler(new MockHandler());
    LogRecord r = new LogRecord(Level.INFO, "testLog_ParentInformed");
    child.setUseParentHandlers(false);
    child.log(r);
    assertFalse(child.getUseParentHandlers());
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger)

Example 33 with LogRecord

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

the class LoggerTest method testConfig_Normal.

/*
	 * Test config(String) with normal values.
	 */
public void testConfig_Normal() {
    this.sharedLogger.setLevel(Level.CONFIG);
    this.sharedLogger.config("config msg");
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), this.sharedLogger.getName());
    assertEquals(r.getMessage(), "config msg");
    assertSame(r.getResourceBundleName(), this.sharedLogger.getResourceBundleName());
    assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.CONFIG);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
    this.sharedLogger.setLevel(Level.INFO);
    this.sharedLogger.config("config again");
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 34 with LogRecord

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

the class LoggerTest method testLog_NullResHasParent.

/*
	 * Test that a logger inherits its parent resource bundle when its resource
	 * bundle is null.
	 */
public void testLog_NullResHasParent() {
    Logger child = new MockLogger("childLogger", null);
    Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.addHandler(new MockHandler());
    child.setParent(parent);
    parent.setLevel(Level.FINER);
    assertNull(child.getResourceBundle());
    assertNull(child.getResourceBundleName());
    child.log(Level.FINE, "testLog_NullResHasParent");
    // pop only once, pushed by the child logger's handler
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), "childLogger");
    assertEquals(r.getMessage(), "testLog_NullResHasParent");
    assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2);
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.FINE);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
    assertNull(child.getResourceBundle());
    assertNull(child.getResourceBundleName());
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger)

Example 35 with LogRecord

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

the class LoggerTest method testLogp_LevelStringStringStringObject_Normal.

/*
	 * Test logp(Level, String, String, String, Object) with normal values.
	 */
public void testLogp_LevelStringStringStringObject_Normal() {
    Object param = new Object();
    this.sharedLogger.setLevel(Level.INFO);
    this.sharedLogger.logp(Level.INFO, "sourceClass", "sourceMethod", "logp(Level, String, String, String, Object) msg", param);
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), this.sharedLogger.getName());
    assertEquals(r.getMessage(), "logp(Level, String, String, String, Object) msg");
    assertSame(r.getResourceBundleName(), this.sharedLogger.getResourceBundleName());
    assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
    assertSame(r.getSourceClassName(), "sourceClass");
    assertSame(r.getSourceMethodName(), "sourceMethod");
    assertSame(r.getLevel(), Level.INFO);
    assertEquals(1, r.getParameters().length);
    assertSame(param, r.getParameters()[0]);
    assertSame(r.getThrown(), null);
    this.sharedLogger.logp(Level.CONFIG, "sourceClass", "sourceMethod", "logp(Level, String, String, String, Object) msg", param);
    assertTrue(CallVerificationStack.getInstance().empty());
    this.sharedLogger.setLevel(Level.OFF);
    this.sharedLogger.logp(Level.OFF, "sourceClass", "sourceMethod", "logp(Level, String, String, String, Object) msg", param);
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord)

Aggregations

LogRecord (java.util.logging.LogRecord)370 Logger (java.util.logging.Logger)62 Test (org.junit.Test)61 Handler (java.util.logging.Handler)24 File (java.io.File)21 IOException (java.io.IOException)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Level (java.util.logging.Level)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 ArrayList (java.util.ArrayList)12 Properties (java.util.Properties)11 Config (com.sun.enterprise.config.serverbeans.Config)10 Formatter (java.util.logging.Formatter)10 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)9 ActionReport (org.glassfish.api.ActionReport)9 HashMap (java.util.HashMap)7 Subscribe (com.google.common.eventbus.Subscribe)6