Search in sources :

Example 1 with LogReport

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;
    }
}
Also used : LogLine(com.peterphi.std.guice.common.logging.logreport.LogLine) LogReport(com.peterphi.std.guice.common.logging.logreport.LogReport)

Example 2 with LogReport

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;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) FilterInputStream(java.io.FilterInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) LogReport(com.peterphi.std.guice.common.logging.logreport.LogReport)

Aggregations

LogReport (com.peterphi.std.guice.common.logging.logreport.LogReport)2 LogLine (com.peterphi.std.guice.common.logging.logreport.LogLine)1 FilterInputStream (java.io.FilterInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1