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);
}
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--;
}
}
}
}
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));
}
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;
}
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"));
}
Aggregations