Skip to content

Commit

Permalink
added HTTP appender
Browse files Browse the repository at this point in the history
  • Loading branch information
osiegmar committed Mar 28, 2024
1 parent b8cb8ff commit bd9ec95
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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
- HTTP appender for sending GELF messages via HTTP

### Changed
- Update dependency to logback 1.5.3
- Renamed shortPatternLayout to shortMessageLayout, fullPatternLayout to fullMessageLayout
Expand Down
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ dependencies.

- UDP (with chunking)
- TCP (with or without TLS encryption)
- Deflate compression in UDP mode
- HTTP(s)
- GZIP and ZLIB compression (in UDP and HTTP mode)
- Client side load balancing (round-robin)
- Forwarding of MDC (Mapped Diagnostic Context)
- Forwarding of caller data
Expand Down Expand Up @@ -91,6 +92,28 @@ Simple TCP with TLS configuration:
</configuration>
```

Simple HTTP configuration:

```xml
<configuration>

<appender name="GELF" class="de.siegmar.logbackgelf.GelfHttpAppender">
<uri>https://my.server:12201/gelf</uri>
</appender>

<!-- Use AsyncAppender to prevent slowdowns -->
<appender name="ASYNC GELF" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="GELF" />
<neverBlock>true</neverBlock>
</appender>

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

</configuration>
```

Find more advanced examples in the [examples directory](examples).

## Configuration
Expand All @@ -102,20 +125,19 @@ Find more advanced examples in the [examples directory](examples).
* **graylogHost**: IP or hostname of graylog server.
If the hostname resolves to multiple ip addresses, round-robin will be used.
* **graylogPort**: Port of graylog server. Default: 12201.
* **encoder**: See Encoder configuration below.
* **maxChunkSize**: Maximum size of GELF chunks in bytes. Default chunk size is 508 - this prevents
IP packet fragmentation. This is also the recommended minimum.
Maximum supported chunk size is 65,467 bytes.
* **compressionMethod**: Compression method to use (NONE, GZIP or ZLIB). Default: GZIP.
* **messageIdSupplier**: The mechanism that supplies unique message ids that are required by the
GELF UDP protocol. Default: `de.siegmar.logbackgelf.MessageIdSupplier`.
* **encoder**: See Encoder configuration below.

`de.siegmar.logbackgelf.GelfTcpAppender`

* **graylogHost**: IP or hostname of graylog server.
If the hostname resolves to multiple ip addresses, round-robin will be used.
* **graylogPort**: Port of graylog server. Default: 12201.
* **encoder**: See Encoder configuration below.
* **connectTimeout**: Maximum time (in milliseconds) to wait for establishing a connection. A value
of 0 disables the connect timeout. Default: 15,000 milliseconds.
* **socketTimeout**: Maximum time (in milliseconds) to block when reading a socket. A value of 0 disables
Expand All @@ -131,13 +153,29 @@ Find more advanced examples in the [examples directory](examples).
* **poolMaxIdleTime**: Maximum amount of time (in seconds) that a pooled connection can be idle
before it is considered 'stale' and will not be reused. A value of -1 disables the max idle time
feature. Default: -1 (disabled).
* **encoder**: See Encoder configuration below.

`de.siegmar.logbackgelf.GelfTcpTlsAppender`

* Everything from GelfTcpAppender
* **insecure**: If true, skip the TLS certificate validation.
You should not use this in production! Default: false.

`de.siegmar.logbackgelf.GelfHttpAppender`

* **uri**: HTTP(s) URI of graylog server (e.g. https://my.server:12201/gelf).
* **insecure**: If true, skip the TLS certificate validation.
You should not use this in production! Default: false.
* **connectTimeout**: Maximum time (in milliseconds) to wait for establishing a connection. A value
of 0 disables the connect timeout. Default: 15,000 milliseconds.
* **requestTimeout**: Maximum time (in milliseconds) to wait for a response. A value of 0 disables the timeout.
Default: 5,000 milliseconds.
* **maxRetries**: Number of retries. A value of 0 disables retry attempts. Default: 2.
* **retryDelay**: Time (in milliseconds) between retry attempts. Ignored if maxRetries is 0.
Default: 3,000 milliseconds.
* **compressionMethod**: Compression method to use (NONE, GZIP or ZLIB). Default: GZIP.
* **encoder**: See Encoder configuration below.

### Encoder

`de.siegmar.logbackgelf.GelfEncoder`
Expand All @@ -160,8 +198,8 @@ Find more advanced examples in the [examples directory](examples).
Default: logger_name.
* **threadNameKey**: The key (i.e. the field name) that should be used for the thread name.
Default: thread_name.
* **appendNewline**: If true, a system dependent newline separator will be added at the end of each message.
Don't use this in conjunction with TCP or UDP appenders, as this is only reasonable for
* **appendNewline**: If true, a system-dependent newline separator will be added at the end of each message.
Don't use this in conjunction with TCP/UDP/HTTP appender, as this is only reasonable for
console logging!
* **shortMessageLayout**: Short message format. Default: `"%m%nopex"`.
* **fullMessageLayout**: Full message format (Stacktrace). Default: `"%m%n"`.
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies {
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:2.38.0")
testImplementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
testImplementation("org.bouncycastle:bcpkix-jdk18on:1.76")
testImplementation("org.wiremock:wiremock:3.4.2")
testImplementation("org.awaitility:awaitility:4.2.1")
}

tasks.test {
Expand Down
1 change: 1 addition & 0 deletions config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<allow pkg="java.math"/>
<allow pkg="java.security"/>
<allow pkg="java.text"/>
<allow pkg="java.time"/>
<allow pkg="java.util"/>

<allow pkg="javax.naming"/>
Expand Down
1 change: 1 addition & 0 deletions config/spotbugs/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Or>
<Class name="de.siegmar.logbackgelf.AbstractGelfAppender"/>
<Class name="de.siegmar.logbackgelf.GelfEncoder"/>
<Class name="de.siegmar.logbackgelf.GelfHttpAppender"/>
</Or>
</Match>

Expand Down
43 changes: 43 additions & 0 deletions examples/advanced_http.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<configuration>

<appender name="GELF" class="de.siegmar.logbackgelf.GelfHttpAppender">
<uri>https://my.server:12201/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>
<includeKeyValues>true</includeKeyValues>
<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>

<appender name="ASYNC GELF" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="GELF" />
<neverBlock>true</neverBlock>
</appender>

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

</configuration>
Loading

0 comments on commit bd9ec95

Please sign in to comment.