diff --git a/logback-correlationid/logback-correlationid.gradle b/logback-correlationid/logback-correlationid.gradle index ba0d7a8d..9a429fce 100644 --- a/logback-correlationid/logback-correlationid.gradle +++ b/logback-correlationid/logback-correlationid.gradle @@ -12,6 +12,7 @@ dependencies { implementation project(":logback-classic") implementation project(":logback-jdbc-appender") implementation project(":logback-uniqueid-appender") + implementation project(":logback-ringbuffer") testImplementation "com.h2database:h2:1.4.200" testImplementation 'org.awaitility:awaitility:4.0.2' diff --git a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedEventEncoder.java b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedEventEncoder.java deleted file mode 100644 index 4337ac68..00000000 --- a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedEventEncoder.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.tersesystems.logback.ringbuffer; - -import ch.qos.logback.classic.layout.TTLLLayout; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; -import ch.qos.logback.core.encoder.Encoder; -import ch.qos.logback.core.encoder.LayoutWrappingEncoder; -import ch.qos.logback.core.spi.ContextAwareBase; - -/** A processed event encoder */ -public class BufferedEventEncoder extends ContextAwareBase implements Encoder { - private boolean started; - - private Encoder encoder; - - public Encoder getEncoder() { - return encoder; - } - - public void setEncoder(Encoder encoder) { - this.encoder = encoder; - } - - @Override - public byte[] headerBytes() { - return new byte[0]; - } - - @Override - public byte[] encode(E event) { - if (event instanceof BufferedLoggingEvent) { - BufferedLoggingEvent bufferedLoggingEvent = (BufferedLoggingEvent) event; - return bufferedLoggingEvent.getEncodedData(); - } else { - return this.encoder.encode(event); - } - } - - @Override - public byte[] footerBytes() { - return new byte[0]; - } - - @Override - public void start() { - if (this.encoder == null) { - addInfo("Null encoder, using the default TTLLLayout"); - this.encoder = defaultEncoder(); - this.encoder.start(); - return; - } - started = true; - } - - @SuppressWarnings("unchecked") - LayoutWrappingEncoder defaultEncoder() { - LayoutWrappingEncoder encoder = new LayoutWrappingEncoder<>(); - encoder.setContext(getContext()); - TTLLLayout layout = new TTLLLayout(); - layout.setContext(getContext()); - layout.start(); - encoder.setLayout(layout); - // Work around for the encoder needing a parent that's an appender :-/ - if (this.parent instanceof Appender) { - encoder.setParent((Appender) this.parent); - } - return (LayoutWrappingEncoder) encoder; - } - - @Override - public void stop() { - this.encoder = null; - started = false; - } - - @Override - public boolean isStarted() { - return this.started; - } - - Object parent; - - public void setParent(Object parent) { - this.parent = parent; - } -} diff --git a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedLoggingEvent.java b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedLoggingEvent.java deleted file mode 100644 index 297241fd..00000000 --- a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedLoggingEvent.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.tersesystems.logback.ringbuffer; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.spi.*; -import java.nio.charset.StandardCharsets; -import java.util.Map; -import org.slf4j.Marker; - -public class BufferedLoggingEvent implements ILoggingEvent { - - private final String loggerName; - private final IThrowableProxy throwableProxy; - private final Level level; - private final String threadName; - private final Map mdcPropertyMap; - private final long timestamp; - private final byte[] encodedData; - - public BufferedLoggingEvent( - String loggerName, - Level level, - byte[] encodedData, - long timestamp, - String threadName, - Map mdcPropertyMap, - IThrowableProxy throwableProxy) { - this.loggerName = loggerName; - this.level = level; - this.encodedData = encodedData; - this.timestamp = timestamp; - this.threadName = threadName; - this.mdcPropertyMap = mdcPropertyMap; - this.throwableProxy = throwableProxy; - } - - // Returns the results of running the event through an encoder. - public byte[] getEncodedData() { - return encodedData; - } - - public String getThreadName() { - return this.threadName; - } - - @Override - public Level getLevel() { - return this.level; - } - - @Override - public String getMessage() { - return null; - } - - @Override - public Object[] getArgumentArray() { - return new Object[0]; - } - - @Override - public String getFormattedMessage() { - return new String(getEncodedData(), StandardCharsets.UTF_8); - } - - @Override - public String getLoggerName() { - return this.loggerName; - } - - @Override - public LoggerContextVO getLoggerContextVO() { - return null; - } - - @Override - public IThrowableProxy getThrowableProxy() { - return throwableProxy; - } - - @Override - public StackTraceElement[] getCallerData() { - return new StackTraceElement[0]; - } - - @Override - public boolean hasCallerData() { - return false; - } - - @Override - public Marker getMarker() { - return null; - } - - @Override - public Map getMDCPropertyMap() { - return this.mdcPropertyMap; - } - - @Override - public Map getMdc() { - return mdcPropertyMap; - } - - @Override - public long getTimeStamp() { - return this.timestamp; - } - - @Override - public void prepareForDeferredProcessing() {} -} diff --git a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedLoggingEventFactory.java b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedLoggingEventFactory.java deleted file mode 100644 index ae3ad97d..00000000 --- a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/BufferedLoggingEventFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.tersesystems.logback.ringbuffer; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.classic.spi.IThrowableProxy; -import java.util.Map; - -/** - * This event factory creates a logging event that has already been encoded. - * - *

Note that the marker and arguments of the events are purposefully left null, because they - * could contain references to outside objects that were not garbage collected. - */ -public class BufferedLoggingEventFactory { - - public BufferedLoggingEvent create(ILoggingEvent event, byte[] encodedData) { - event.prepareForDeferredProcessing(); - IThrowableProxy throwableProxy = event.getThrowableProxy(); - String loggerName = event.getLoggerName(); - String threadName = event.getThreadName(); - Map mdcPropertyMap = event.getMDCPropertyMap(); - long timestamp = event.getTimeStamp(); - Level level = event.getLevel(); - return new BufferedLoggingEvent( - loggerName, level, encodedData, timestamp, threadName, mdcPropertyMap, throwableProxy); - } -} diff --git a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/MessagePassingQueueRingBuffer.java b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/MessagePassingQueueRingBuffer.java index 4c8371dd..d9d734be 100644 --- a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/MessagePassingQueueRingBuffer.java +++ b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/MessagePassingQueueRingBuffer.java @@ -4,6 +4,7 @@ import org.jctools.queues.MessagePassingQueue; import org.jctools.queues.MpmcArrayQueue; +/** An implementation of ring buffer using a multi-producer/multi-consumer array queue. */ public class MessagePassingQueueRingBuffer extends RingBufferBase { // https://psy-lob-saw.blogspot.com/2015/01/mpmc-multi-multi-queue-vs-clq.html diff --git a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/RingBufferAwareAppender.java b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/RingBufferAwareAppender.java index 3acff372..3618d75d 100644 --- a/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/RingBufferAwareAppender.java +++ b/logback-ringbuffer/src/main/java/com/tersesystems/logback/ringbuffer/RingBufferAwareAppender.java @@ -1,7 +1,6 @@ package com.tersesystems.logback.ringbuffer; import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.encoder.Encoder; import ch.qos.logback.core.spi.AppenderAttachableImpl; import ch.qos.logback.core.spi.FilterReply; import com.tersesystems.logback.core.DefaultAppenderAttachable; @@ -11,26 +10,12 @@ public class RingBufferAwareAppender extends AbstractRingBufferAppender implements DefaultAppenderAttachable { - protected final BufferedLoggingEventFactory eventFactory = new BufferedLoggingEventFactory(); - - private Encoder encoder; - private final AppenderAttachableImpl aai = new AppenderAttachableImpl<>(); // Provide a transform function we can override in subclasses - protected Function transformFunction = - e -> { - byte[] encodedData = getEncoder().encode(e); - return eventFactory.create(e, encodedData); - }; - - public Encoder getEncoder() { - return encoder; - } - - public void setEncoder(Encoder encoder) { - this.encoder = encoder; - } + // This gives us the option of doing encoding or isolating event logic without requiring + // anything at base level + protected Function transformFunction = Function.identity(); @Override public AppenderAttachableImpl appenderAttachableImpl() { @@ -47,10 +32,6 @@ public void setTransformFunction(Function transfor @Override public void start() { - if (this.encoder == null) { - addError("Null encoder!"); - return; - } super.start(); }