/** * Actual writing occurs here. * <p> * Most subclasses of <code>WriterAppender</code> will need to override this * method. * * @since 0.9.0 */ protected void subAppend(E event) { if (!isStarted()) { return; } try { // this step avoids LBCLASSIC-139 if (event instanceof DeferredProcessingAware) { ((DeferredProcessingAware) event).prepareForDeferredProcessing(); } // the synchronization prevents the OutputStream from being closed while we // are writing. It also prevents multiple threads from entering the same // converter. Converters assume that they are in a synchronized block. lock.lock(); try { writeOut(event); } finally { lock.unlock(); } } catch (IOException ioe) { // as soon as an exception occurs, move to non-started state // and add a single ErrorStatus to the SM. this.started = false; addStatus(new ErrorStatus("IO failure in appender", this, ioe)); } }
@Override protected synchronized void append(final E event) { if (!isStarted()) { return; } try { if (event instanceof DeferredProcessingAware) { ((DeferredProcessingAware) event).prepareForDeferredProcessing(); } this.encoder.doEncode(event); } catch (final IOException ex) { stop(); addStatus(new ErrorStatus("IO failure in appender named \"" + this.name + "\".", this, ex)); } }
/** * * @param eventObject */ private void subAppend(ILoggingEvent eventObject) { if (!isStarted()) { return; } try { // this step avoids LBCLASSIC-139 if (eventObject instanceof DeferredProcessingAware) { ((DeferredProcessingAware) eventObject).prepareForDeferredProcessing(); } this.encoder.doEncode(eventObject); } catch (IOException ioe) { this.started = false; addStatus(new ErrorStatus("IO failure in appender", this, ioe)); } }
@Override public void writeTo(JsonGenerator generator, DeferredProcessingAware deferredProcessingAware) throws IOException { generator.writeFieldName("service"); generator.writeString(serviceName); generator.writeFieldName("service-version"); generator.writeString(serviceVersion); generator.writeFieldName("service-id"); generator.writeString(serviceInstanceId); }
private <T extends DeferredProcessingAware> AbstractFieldJsonProvider<T> withName( String name, AbstractFieldJsonProvider<T> provider, LoggerContext context ) { provider.setContext(context); provider.setFieldName(name); return provider; }
/** * Appends an event in order to be logged. This method is unsafe concerning the fact that the event is lost * if the Jedis client connection has timed out due to a redis connection timeout (configured on the * redis server). * * @param event event to be appended */ private void appendUnsafe(DeferredProcessingAware event) { if (event != null) { rpushAndSyncIfBatchFinished(event); } else { sendBatch(batchConfig.getProcessedBatchItemsCount()); } }
private void rpushAndSyncIfBatchFinished(DeferredProcessingAware event) { pipeline.rpush(connectionConfig.getKey(), createEncodedEvent(event)); batchConfig.addBatchItem(); final int batchSize = batchConfig.getProcessedBatchItemsCount(); if (batchConfig.isBatchFinished()) { sendBatch(batchSize); } }
private String createEncodedEvent(DeferredProcessingAware event) { try (ByteArrayOutputStream eventOutputStream = new ByteArrayOutputStream(BUFFER_SIZE)) { encoder.init(eventOutputStream); encoder.doEncode(event); return eventOutputStream.toString("UTF-8"); } catch (IOException e) { throw new IllegalStateException("error while initializing the event encoder", e); } }
private void subAppend(E event) { if (event instanceof DeferredProcessingAware) { ((DeferredProcessingAware) event).prepareForDeferredProcessing(); } append(this.encoder.encode(event)); }
public Encoder<DeferredProcessingAware> getEncoder() { return encoder; }
public void setEncoder(Encoder<DeferredProcessingAware> encoder) { this.encoder = encoder; }