Search in sources :

Example 41 with LogRecord

use of java.util.logging.LogRecord in project roboguice by roboguice.

the class BinderTest method testUserReportedErrorsAreAlsoLogged.

public void testUserReportedErrorsAreAlsoLogged() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                addError(new Message("Whoops!", new IllegalArgumentException()));
            }
        });
        fail();
    } catch (CreationException expected) {
    }
    LogRecord logRecord = Iterables.getOnlyElement(this.logRecords);
    assertContains(logRecord.getMessage(), "An exception was caught and reported. Message: java.lang.IllegalArgumentException");
}
Also used : Message(com.google.inject.spi.Message) LogRecord(java.util.logging.LogRecord) CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 42 with LogRecord

use of java.util.logging.LogRecord in project flyway by flyway.

the class JavaUtilLog method log.

/**
     * Log the message at the specified level with the specified exception if any.
     *
     * @param level The level to log at.
     * @param message The message to log.
     * @param e The exception, if any.
     */
private void log(Level level, String message, Exception e) {
    // millis and thread are filled by the constructor
    LogRecord record = new LogRecord(level, message);
    record.setLoggerName(logger.getName());
    record.setThrown(e);
    record.setSourceClassName(logger.getName());
    record.setSourceMethodName(getMethodName());
    logger.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 43 with LogRecord

use of java.util.logging.LogRecord in project guava by hceylan.

the class TestLogHandlerTest method test.

public void test() throws Exception {
    assertTrue(handler.getStoredLogRecords().isEmpty());
    ExampleClassUnderTest.foo();
    LogRecord record = handler.getStoredLogRecords().iterator().next();
    assertEquals(Level.INFO, record.getLevel());
    assertEquals("message", record.getMessage());
    assertSame(EXCEPTION, record.getThrown());
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 44 with LogRecord

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

the class LoggerTest method testSevere_Null.

/*
	 * Test severe(String) with null values.
	 */
public void testSevere_Null() {
    Logger child = new MockLogger("childLogger", null);
    Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
    child.addHandler(new MockHandler());
    child.setParent(parent);
    child.setLevel(Level.SEVERE);
    child.severe(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.SEVERE);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
    this.sharedLogger.setLevel(Level.OFF);
    this.sharedLogger.severe(null);
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger)

Example 45 with LogRecord

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

the class LoggerTest method testLogrb_LevelStringTStringStringhrowable_NullMsgObj.

/*
	 * Test logrb(Level, String, String, String, String, Throwable) with null
	 * message and throwable.
	 */
public void testLogrb_LevelStringTStringStringhrowable_NullMsgObj() {
    this.sharedLogger.setLevel(Level.INFO);
    this.sharedLogger.logrb(Level.INFO, null, null, null, null, (Throwable) null);
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), this.sharedLogger.getName());
    assertNull(r.getMessage());
    assertSame(r.getResourceBundleName(), null);
    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)

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