Search in sources :

Example 6 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class JavaUtilsLoggingBuildListener method ruleSuspended.

@Subscribe
public void ruleSuspended(BuildRuleEvent.Suspended suspended) {
    LogRecord record = new LogRecord(LEVEL, suspended.toString());
    record.setMillis(suspended.getTimestamp());
    LOG.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord) Subscribe(com.google.common.eventbus.Subscribe)

Example 7 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class MemoryHandler method publish.

@Override
public void publish(LogRecord record) {
    if (!isLoggable(record)) {
        return;
    }
    List<LogRecord> recordsToLog = null;
    synchronized (buffer) {
        int ix = (start + count) % buffer.length;
        buffer[ix] = record;
        if (count < buffer.length) {
            count++;
        } else {
            start++;
            start %= buffer.length;
        }
        if (record.getLevel().intValue() >= pushLevel.intValue()) {
            recordsToLog = new ArrayList<>();
            while (count > 0) {
                LogRecord oldRecord = buffer[start];
                recordsToLog.add(oldRecord);
                buffer[start] = null;
                start++;
                start %= buffer.length;
                count--;
            }
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 8 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class ConsoleHandlerTest method consoleHandlerDoesNotWriteBelowLevelToStream.

@Test
public void consoleHandlerDoesNotWriteBelowLevelToStream() {
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream), new MessageOnlyFormatter(), Level.INFO, state);
    publishAndFlush(handler, new LogRecord(Level.FINE, "Shh.."));
    assertThat(outputStream.size(), equalTo(0));
}
Also used : LogRecord(java.util.logging.LogRecord) Test(org.junit.Test)

Example 9 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class LogFormatterTest method logRecord.

private static LogRecord logRecord(Level level, String message, String loggerName, int tid, long millis) {
    LogRecord result = new LogRecord(level, message);
    result.setLoggerName(loggerName);
    result.setMillis(millis);
    result.setThreadID(tid);
    return result;
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 10 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class ConsoleHandlerTest method consoleHandlerCanChangeOutputStreamWithoutClosing.

@Test
public void consoleHandlerCanChangeOutputStreamWithoutClosing() throws IOException {
    FakeOutputStream outputStream1 = new FakeOutputStream();
    FakeOutputStream outputStream2 = new FakeOutputStream();
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream1), new MessageOnlyFormatter(), Level.INFO, state);
    publishAndFlush(handler, new LogRecord(Level.INFO, "Stream 1"));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1"));
    threadIdToCommandId.put(49152L, "commandIdForOutputStream2");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    assertThat(outputStream1.isClosed(), equalTo(false));
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 2", 49152));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1"));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
    unregisterOutputStream("commandIdForOutputStream2");
    assertThat(outputStream2.isClosed(), equalTo(false));
    publishAndFlush(handler, new LogRecord(Level.INFO, " - DONE"));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1 - DONE"));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
}
Also used : LogRecord(java.util.logging.LogRecord) FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) 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