Search in sources :

Example 16 with LogRecord

use of java.util.logging.LogRecord in project generator by mybatis.

the class JdkLoggingImpl method error.

public void error(String s, Throwable e) {
    LogRecord lr = new LogRecord(Level.SEVERE, s);
    lr.setSourceClassName(log.getName());
    lr.setThrown(e);
    log.log(lr);
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 17 with LogRecord

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

the class JdkLogger method log.

/**
     * Log the message at the specified level with the specified throwable if any.
     * This method creates a LogRecord and fills in caller date before calling
     * this instance's JDK14 logger.
     *
     * See bug report #13 for more details.
     */
private void log(String callerFQCN, Level level, String msg, Throwable t) {
    // millis and thread are filled by the constructor
    LogRecord record = new LogRecord(level, msg);
    record.setLoggerName(name());
    record.setThrown(t);
    fillCallerData(callerFQCN, record);
    logger.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 18 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 19 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 20 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)

Aggregations

LogRecord (java.util.logging.LogRecord)289 Test (org.junit.Test)53 Logger (java.util.logging.Logger)45 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Handler (java.util.logging.Handler)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 File (java.io.File)12 Properties (java.util.Properties)11 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 Formatter (java.util.logging.Formatter)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Subscribe (com.google.common.eventbus.Subscribe)6 HashMap (java.util.HashMap)6 Level (java.util.logging.Level)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 FileHandler (java.util.logging.FileHandler)5 Filter (java.util.logging.Filter)4