Skip to content

Commit

Permalink
add support for external encoders
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Aug 30, 2024
1 parent 9fc8f6b commit 5e5a5f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Support for external encoders like Spring's StructuredLogEncoder

## [6.0.2] - 2024-08-24
### Changed
- Improve performance of number conversion in GelfEncoder (#108); Thanks to [@deathy](https://github.com/deathy)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "de.siegmar"
version = "6.0.2"
version = "6.1.0-SNAPSHOT"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
import ch.qos.logback.core.encoder.Encoder;

public abstract class AbstractGelfAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {

Expand All @@ -38,7 +39,7 @@ public abstract class AbstractGelfAppender extends UnsynchronizedAppenderBase<IL
*/
private int graylogPort = DEFAULT_GELF_PORT;

private GelfEncoder encoder;
private Encoder<ILoggingEvent> encoder;

public String getGraylogHost() {
return graylogHost;
Expand All @@ -56,11 +57,11 @@ public void setGraylogPort(final int graylogPort) {
this.graylogPort = graylogPort;
}

public GelfEncoder getEncoder() {
public Encoder<ILoggingEvent> getEncoder() {
return encoder;
}

public void setEncoder(final GelfEncoder encoder) {
public void setEncoder(final Encoder<ILoggingEvent> encoder) {
this.encoder = encoder;
}

Expand All @@ -76,7 +77,7 @@ public final void start() {
encoder = new GelfEncoder();
encoder.setContext(getContext());
encoder.start();
} else if (encoder.isAppendNewline()) {
} else if (encoder instanceof GelfEncoder && ((GelfEncoder) encoder).isAppendNewline()) {
addError("Newline separator must not be enabled in layout");
return;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/de/siegmar/logbackgelf/GelfHttpAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
import ch.qos.logback.core.encoder.Encoder;
import de.siegmar.logbackgelf.compressor.Compressor;

@SuppressWarnings("checkstyle:ClassFanOutComplexity")
Expand Down Expand Up @@ -90,7 +91,7 @@ public class GelfHttpAppender extends UnsynchronizedAppenderBase<ILoggingEvent>
/**
* The encoder to use for encoding log messages.
*/
private GelfEncoder encoder;
private Encoder<ILoggingEvent> encoder;

private Compressor compressor;

Expand Down Expand Up @@ -158,11 +159,11 @@ public void setHttpClient(final HttpClient httpClient) {
this.httpClient = httpClient;
}

public GelfEncoder getEncoder() {
public Encoder<ILoggingEvent> getEncoder() {
return encoder;
}

public void setEncoder(final GelfEncoder encoder) {
public void setEncoder(final Encoder<ILoggingEvent> encoder) {
this.encoder = encoder;
}

Expand All @@ -177,7 +178,7 @@ public void start() {
encoder = new GelfEncoder();
encoder.setContext(getContext());
encoder.start();
} else if (encoder.isAppendNewline()) {
} else if (encoder instanceof GelfEncoder && ((GelfEncoder) encoder).isAppendNewline()) {
addError("Newline separator must not be enabled in layout");
return;
}
Expand Down

0 comments on commit 5e5a5f0

Please sign in to comment.