Skip to content

Commit

Permalink
fix GelfHttpAppender initialization (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Apr 13, 2024
1 parent 2df33eb commit 971f701
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/main/java/de/siegmar/logbackgelf/GelfHttpAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public class GelfHttpAppender extends UnsynchronizedAppenderBase<ILoggingEvent>

private Compressor compressor;

public URI getUri() {
return uri;
public String getUri() {
return uri.toString();
}

public void setUri(final URI uri) {
this.uri = uri;
public void setUri(final String uri) {
this.uri = URI.create(uri);
}

public boolean isInsecure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static org.awaitility.Awaitility.await;

import java.net.URI;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -98,7 +96,7 @@ private GelfHttpAppender buildAppender(final LoggerContext lc, final GelfEncoder
final GelfHttpAppender gelfAppender = new GelfHttpAppender();
gelfAppender.setContext(lc);
gelfAppender.setName("GELF");
gelfAppender.setUri(URI.create(String.format("http://localhost:%d/gelf", WIRE_MOCK.getPort())));
gelfAppender.setUri(String.format("http://localhost:%d/gelf", WIRE_MOCK.getPort()));
gelfAppender.setEncoder(gelfEncoder);
gelfAppender.start();
return gelfAppender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void xmlConfiguration(final Path file) throws JoranException {
}

static Stream<Path> xmlConfiguration() {
return Stream.of("udp-config.xml", "tcp-config.xml", "tcp_tls-config.xml")
return Stream.of("udp-config.xml", "tcp-config.xml", "tcp_tls-config.xml", "http-config.xml")
.map(name -> Path.of("src", "test", "resources", name));
}

Expand Down
37 changes: 37 additions & 0 deletions src/test/resources/http-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<configuration>

<appender name="GELF" class="de.siegmar.logbackgelf.GelfHttpAppender">
<uri>http://localhost/gelf</uri>
<insecure>false</insecure>
<connectTimeout>15000</connectTimeout>
<requestTimeout>5000</requestTimeout>
<maxRetries>2</maxRetries>
<retryDelay>3000</retryDelay>
<compressionMethod>GZIP</compressionMethod>
<encoder class="de.siegmar.logbackgelf.GelfEncoder">
<originHost>localhost</originHost>
<includeRawMessage>false</includeRawMessage>
<includeMarker>false</includeMarker>
<includeMdcData>true</includeMdcData>
<includeCallerData>false</includeCallerData>
<includeRootCauseData>false</includeRootCauseData>
<includeLevelName>false</includeLevelName>
<shortMessageLayout class="ch.qos.logback.classic.PatternLayout">
<pattern>%m%nopex</pattern>
</shortMessageLayout>
<fullMessageLayout class="ch.qos.logback.classic.PatternLayout">
<pattern>%m%n</pattern>
</fullMessageLayout>
<numbersAsString>false</numbersAsString>
<staticField>app_name:backend</staticField>
<staticField>os_arch:${os.arch}</staticField>
<staticField>os_name:${os.name}</staticField>
<staticField>os_version:${os.version}</staticField>
</encoder>
</appender>

<root level="debug">
<appender-ref ref="GELF" />
</root>

</configuration>

0 comments on commit 971f701

Please sign in to comment.