Search in sources :

Example 1 with InputLogEvent

use of com.amazonaws.services.logs.model.InputLogEvent in project cas by apereo.

the class CloudWatchAppender method flush.

private void flush() {
    int drained;
    final List<InputLogEvent> logEvents = new ArrayList<>(AWS_DRAIN_LIMIT);
    do {
        drained = queue.drainTo(logEvents, AWS_DRAIN_LIMIT);
        if (logEvents.isEmpty()) {
            break;
        }
        Collections.sort(logEvents, Comparator.comparing(InputLogEvent::getTimestamp));
        if (lastReportedTimestamp > 0) {
            for (final InputLogEvent event : logEvents) {
                if (event.getTimestamp() < lastReportedTimestamp) {
                    event.setTimestamp(lastReportedTimestamp);
                }
            }
        }
        lastReportedTimestamp = logEvents.get(logEvents.size() - 1).getTimestamp();
        final PutLogEventsRequest putLogEventsRequest = new PutLogEventsRequest(logGroupName, logStreamName, logEvents);
        putLogEventsRequest.setSequenceToken(sequenceTokenCache);
        try {
            final PutLogEventsResult putLogEventsResult = awsLogsClient.putLogEvents(putLogEventsRequest);
            sequenceTokenCache = putLogEventsResult.getNextSequenceToken();
        } catch (final DataAlreadyAcceptedException daae) {
            sequenceTokenCache = daae.getExpectedSequenceToken();
        } catch (final InvalidSequenceTokenException iste) {
            sequenceTokenCache = iste.getExpectedSequenceToken();
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        logEvents.clear();
    } while (drained >= AWS_DRAIN_LIMIT);
}
Also used : InvalidSequenceTokenException(com.amazonaws.services.logs.model.InvalidSequenceTokenException) InputLogEvent(com.amazonaws.services.logs.model.InputLogEvent) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) ArrayList(java.util.ArrayList) DataAlreadyAcceptedException(com.amazonaws.services.logs.model.DataAlreadyAcceptedException) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) InvalidSequenceTokenException(com.amazonaws.services.logs.model.InvalidSequenceTokenException) DataAlreadyAcceptedException(com.amazonaws.services.logs.model.DataAlreadyAcceptedException)

Example 2 with InputLogEvent

use of com.amazonaws.services.logs.model.InputLogEvent in project cas by apereo.

the class CloudWatchAppender method append.

@Override
public void append(final LogEvent logEvent) {
    final LogEvent event = LoggingUtils.prepareLogEvent(logEvent);
    final InputLogEvent awsLogEvent = new InputLogEvent();
    final long timestamp = event.getTimeMillis();
    final String message = new String(getLayout().toByteArray(event));
    awsLogEvent.setTimestamp(timestamp);
    awsLogEvent.setMessage(message);
    if (!queue.offer(awsLogEvent) && !queueFull) {
        queueFull = true;
    } else if (queueFull) {
        queueFull = false;
    }
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) InputLogEvent(com.amazonaws.services.logs.model.InputLogEvent) InputLogEvent(com.amazonaws.services.logs.model.InputLogEvent)

Aggregations

InputLogEvent (com.amazonaws.services.logs.model.InputLogEvent)2 DataAlreadyAcceptedException (com.amazonaws.services.logs.model.DataAlreadyAcceptedException)1 InvalidSequenceTokenException (com.amazonaws.services.logs.model.InvalidSequenceTokenException)1 PutLogEventsRequest (com.amazonaws.services.logs.model.PutLogEventsRequest)1 PutLogEventsResult (com.amazonaws.services.logs.model.PutLogEventsResult)1 ArrayList (java.util.ArrayList)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1