Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Adjust the KafkaAppender #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
target
.idea
*.iml
*.iml
.settings/org.eclipse.m2e.core.prefs
.settings/org.eclipse.jdt.apt.core.prefs
.classpath
.project
.settings/org.eclipse.core.resources.prefs
.settings/org.eclipse.jdt.core.prefs
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
</issueManagement>

<scm>
<connection>scm:git:git@github.com:danielwegener/logback-kafka-appender.git</connection>
<developerConnection>scm:git:git@github.com:danielwegener/logback-kafka-appender.git</developerConnection>
<url>git@github.com:danielwegener/logback-kafka-appender.git</url>
<connection>scm:git:git@github.com:koekj/logback-kafka-appender.git</connection>
<developerConnection>scm:git:git@github.com:koekj/logback-kafka-appender.git</developerConnection>
<url>git@github.com:koekj/logback-kafka-appender.git</url>
<tag>HEAD</tag>
</scm>

Expand Down
12 changes: 12 additions & 0 deletions release.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#release configuration
#Tue Dec 17 08:33:05 CET 2019
projectVersionPolicyId=default
scm.tagNameFormat=@{project.artifactId}-@{project.version}
exec.additionalArguments=\ -Psonatype-oss-release
remoteTagging=true
scm.commentPrefix=[maven-release-plugin]
pushChanges=true
completedPhase=check-poms
scm.url=scm\:git\:git@github.com\:koekj/logback-kafka-appender.git
exec.snapshotReleasePluginAllowed=false
preparationGoals=clean verify
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class KafkaAppender<E> extends KafkaAppenderConfig<E> {
* Kafka clients uses this prefix for its slf4j logging.
* This appender defers appends of any Kafka logs since it could cause harmful infinite recursion/self feeding effects.
*/
private static final String KAFKA_LOGGER_PREFIX = KafkaProducer.class.getPackage().getName().replaceFirst("\\.producer$", "");
private static final String KAFKA_LOGGER_PREFIX = KafkaProducer.class.getPackage().getName().replaceFirst("\\.clients\\.producer$", "");

private LazyProducer lazyProducer = null;
private final AppenderAttachableImpl<E> aai = new AppenderAttachableImpl<E>();
Expand All @@ -46,7 +46,10 @@ public KafkaAppender() {
public void doAppend(E e) {
ensureDeferredAppends();
if (e instanceof ILoggingEvent && ((ILoggingEvent)e).getLoggerName().startsWith(KAFKA_LOGGER_PREFIX)) {
deferAppend(e);
//only in case the producer is initialized we are able to send messages.
if ( (lazyProducer != null ) && lazyProducer.isInitialized() ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this condition should rather guard the ensureDeferredAppends();in line 47, not? Buffering up messages in deferAppend while the producer is not initialized is somewhat intentional

deferAppend(e);
}
} else {
super.doAppend(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public void testDeferredAppend() {

final LoggingEvent evt = new LoggingEvent("fqcn",ctx.getLogger("logger"), Level.ALL, "message", null, new Object[0]);
unit.doAppend(evt);
verify(deliveryStrategy).send(any(KafkaProducer.class), any(ProducerRecord.class), eq(deferredEvent), any(FailedDeliveryCallback.class));
verify(deliveryStrategy).send(any(KafkaProducer.class), any(ProducerRecord.class), eq(evt), any(FailedDeliveryCallback.class));
}

Expand All @@ -147,7 +146,7 @@ public void testKafkaLoggerPrefix() throws ReflectiveOperationException {
constField.setAccessible(true);
}
String constValue = (String) constField.get(null);
assertThat(constValue, equalTo("org.apache.kafka.clients"));
assertThat(constValue, equalTo("org.apache.kafka"));
}


Expand Down