Search in sources :

Example 66 with LogRecord

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

the class LoggerTest method testLog_LevelStringObject_Normal.

/*
	 * Test log(Level, String, Object) with normal values.
	 */
public void testLog_LevelStringObject_Normal() {
    Object param = new Object();
    this.sharedLogger.setLevel(Level.INFO);
    this.sharedLogger.log(Level.INFO, "log(Level, String, Object) msg", param);
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), this.sharedLogger.getName());
    assertEquals(r.getMessage(), "log(Level, String, Object) 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);
    assertEquals(1, r.getParameters().length);
    assertSame(param, r.getParameters()[0]);
    assertSame(r.getThrown(), null);
    this.sharedLogger.log(Level.CONFIG, "log(Level, String, Object) msg", param);
    assertTrue(CallVerificationStack.getInstance().empty());
    this.sharedLogger.setLevel(Level.OFF);
    this.sharedLogger.log(Level.OFF, "log(Level, String, Object) msg", param);
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 67 with LogRecord

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

the class WithNestedTestClass method setupNested.

@BeforeClass
public static final void setupNested() throws IOException {
    runningNested = true;
    zombieToken = new Object();
    // capture sysout/ syserr.
    sw = new StringWriter();
    sysout = System.out;
    syserr = System.err;
    System.setOut(new PrintStream(new TeeOutputStream(System.out, new WriterOutputStream(sw))));
    System.setErr(new PrintStream(new TeeOutputStream(System.err, new WriterOutputStream(sw))));
    // Add custom logging handler because java logging keeps a reference to previous System.err.
    loggingMessages = new StringWriter();
    logger = Logger.getLogger("");
    handlers = logger.getHandlers();
    for (Handler h : handlers) logger.removeHandler(h);
    logger.addHandler(new Handler() {

        final SimpleFormatter formatter = new SimpleFormatter();

        @Override
        public void publish(LogRecord record) {
            loggingMessages.write(formatter.format(record) + "\n");
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) LogRecord(java.util.logging.LogRecord) SimpleFormatter(java.util.logging.SimpleFormatter) Handler(java.util.logging.Handler) BeforeClass(org.junit.BeforeClass)

Example 68 with LogRecord

use of java.util.logging.LogRecord in project byte-buddy by raphw.

the class ByteBuddyLogHandlerTest method testLogPublishDebug.

@Test
public void testLogPublishDebug() throws Exception {
    ByteBuddyLogHandler byteBuddyLogHandler = new ByteBuddyLogHandler(log, mock(Logger.class), false);
    LogRecord logRecord = new LogRecord(Level.INFO, FOO);
    when(log.isDebugEnabled()).thenReturn(true);
    byteBuddyLogHandler.publish(logRecord);
    verify(log).isDebugEnabled();
    verify(log).debug(byteBuddyLogHandler.getFormatter().format(logRecord));
    verifyNoMoreInteractions(log);
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 69 with LogRecord

use of java.util.logging.LogRecord in project byte-buddy by raphw.

the class ByteBuddyLogHandlerTest method testLogPublishNoDebug.

@Test
public void testLogPublishNoDebug() throws Exception {
    ByteBuddyLogHandler byteBuddyLogHandler = new ByteBuddyLogHandler(log, mock(Logger.class), false);
    LogRecord logRecord = new LogRecord(Level.INFO, FOO);
    byteBuddyLogHandler.publish(logRecord);
    verify(log).isDebugEnabled();
    verifyNoMoreInteractions(log);
}
Also used : LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 70 with LogRecord

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

the class OldFileHandlerTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    manager.reset();
    //initProp
    props.clear();
    props.put("java.util.logging.FileHandler.level", "FINE");
    props.put("java.util.logging.FileHandler.filter", className + "$MockFilter");
    props.put("java.util.logging.FileHandler.formatter", className + "$MockFormatter");
    props.put("java.util.logging.FileHandler.encoding", "iso-8859-1");
    // limit to only two message
    props.put("java.util.logging.FileHandler.limit", "1000");
    // rotation count is 2
    props.put("java.util.logging.FileHandler.count", "2");
    // using append mode
    props.put("java.util.logging.FileHandler.append", "true");
    props.put("java.util.logging.FileHandler.pattern", "%t/log/java%u.test");
    HOMEPATH = System.getProperty("user.home");
    TEMPPATH = System.getProperty("java.io.tmpdir");
    File file = new File(TEMPPATH + SEP + "log");
    file.mkdir();
    manager.readConfiguration(propertiesToInputStream(props));
    handler = new FileHandler();
    r = new LogRecord(Level.CONFIG, "msg");
}
Also used : LogRecord(java.util.logging.LogRecord) File(java.io.File) FileHandler(java.util.logging.FileHandler)

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