use of com.peterphi.std.guice.common.logging.logreport.LogReport in project stdlib by petergeneric.
the class ServiceManagerLogForwardDaemon method forwardLogs.
private int forwardLogs(LinkedList<LogLine> source) {
if (!registered)
// cannot forward logs, not yet registered!
return 0;
// Take a page of logs from the incoming stream
final LogLine[] array;
synchronized (source) {
array = new LogLine[Math.min(pageSize, source.size())];
for (int i = 0; i < array.length; i++) array[i] = source.poll();
}
// Forward to the network log receiver
try {
LogReport report = new LogReport();
report.setServiceId(instanceId);
report.setLines(array);
logService.report(report);
// return the number of lines forwarded
return array.length;
} catch (Throwable t) {
// Put the logs that we failed to send back into the queue again
synchronized (source) {
source.addAll(0, Arrays.asList(array));
}
// N.B. we don't use log4j here because the logs will just grow the backlog of messages if there's a permanent problem
log.warn("Service Manager Logging failed to send logs to the network receiver", t);
// 0 lines forwarded
return 0;
}
}
use of com.peterphi.std.guice.common.logging.logreport.LogReport in project stdlib by petergeneric.
the class LogReportMessageBodyReader method readFrom.
@Override
public LogReport readFrom(final Class<LogReport> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
// Make sure we don't close the input stream
entityStream = new FilterInputStream(entityStream) {
@Override
public void close() throws IOException {
log.trace("Ignoring attempt to close stream as part of LogReportMessageBodyReader");
}
};
try {
final InputStream is;
if (GZIP)
is = new GZIPInputStream(entityStream);
else
is = entityStream;
final byte[] buffer = IOUtils.toByteArray(is);
LogReport report = new LogReport();
report.unmarshal(buffer, 0);
return report;
} catch (Throwable t) {
log.warn("Error reading LogReport from input stream", t);
throw t;
}
}
Aggregations