https://github.com/coditory/logback-filters
Additional logback filters
https://github.com/coditory/logback-filters
Last synced: 2 months ago
JSON representation
Additional logback filters
- Host: GitHub
- URL: https://github.com/coditory/logback-filters
- Owner: coditory
- License: mit
- Created: 2021-02-06T22:28:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2026-02-02T02:56:49.000Z (2 months ago)
- Last Synced: 2026-02-02T12:32:32.145Z (2 months ago)
- Language: Groovy
- Size: 191 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Logback Filters
[](https://github.com/coditory/logback-filters/actions/workflows/build.yml)
[](https://codecov.io/gh/coditory/logback-filters)
[](https://mvnrepository.com/artifact/com.coditory.common/logback-filters)
Additional [filters](http://logback.qos.ch/manual/filters.html) for [Logback](http://logback.qos.ch) - Java logging
framework.
## Installation
Add to your `build.gradle`:
```gradle
dependencies {
implementation "com.coditory.logback:logback-filters:0.1.2"
}
```
## AggregatingTurboFilter
Logback filter that aggregates multiple logs into single one. This filter was extracted
from [Hermes (message broker)](https://github.com/allegro/hermes/blob/master/hermes-common/src/main/java/pl/allegro/tech/hermes/infrastructure/logback/AggregatingTurboFilter.java)
and enriched with new capabilities.
Filter options:
- `reportingIntervalMillis` - time interval in which logs are passed to output. Be default, interval is set up to `10s`.
- `aggregationMessageToken` - token in the log message that triggers aggregation. By default, token filtration is
disabled.
- `aggregatedLogger` - list of loggers that have aggregated logs
Filter drawbacks:
- Aggregated logs are not reported in order
- Aggregated logs have the same thread name `aggregating-filter-%d-thread-0`. `%d` is replaced with filter index in case
there are multiple `AggregatingTurboFilters` defined.
Sample configuration:
```xml
3000
com.coditory.sandbox.Sandbox
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{10} - %msg%n
```
## Aggregate by log message
To aggregate over 3s logs from `com.coditory.sandbox.SomeClass` by log message (with resolved parameters) use following
configuration:
```xml
3000
com.coditory.sandbox.Sandbox
```
Example:
```java
@Slf4j
class Sandbox {
public static void main(String[] args) throws InterruptedException {
log.info("Hello {}", "James");
log.info("Hello {}", "Harry");
log.info("Hello {}", "James");
log.info("Hello {}", "Mary");
log.info("Hello {}", "Mary", new RuntimeException("error"));
log.info("Hello {}", "Mary");
Thread.sleep(5000);
}
}
// Output:
// 16:50:39.632 [aggregating-filter-0-thread-0] INFO c.c.s.Sandbox - Hello Mary [occurrences=3]
// java.lang.RuntimeException: error
// at com.coditory.sandbox.Sandbox.main(Sandbox.java:14)
// 16:50:39.638 [aggregating-filter-0-thread-0] INFO c.c.s.Sandbox - Hello James [occurrences=2]
// 16:50:39.638 [aggregating-filter-0-thread-0] INFO c.c.s.Sandbox - Hello Harry [occurrences=1]
```
## Aggregate by log template
To aggregate logs from `com.coditory.sandbox.SomeClass` by log message template (without resolved parameters):
```xml
template
com.coditory.sandbox.SomeClass
```
Example:
```java
@Slf4j
class Sandbox {
public static void main(String[] args) throws InterruptedException {
log.info("Hello {}", "Mary");
log.info("Hello {}", "Mary", new RuntimeException("error"));
log.info("Hello {}", "Mary");
log.info("Hello {}", "James");
log.info("Hello {}", "Harry");
log.info("Hello {}", "James");
Thread.sleep(5000);
}
}
// Output:
// 16:49:50.244 [aggregating-filter-0-thread-0] INFO c.c.s.Sandbox - Hello Mary [occurrences=6]
// java.lang.RuntimeException: error
// at com.coditory.sandbox.Sandbox.main(Sandbox.java:11)
```
## Aggregate log messages with aggregation token
To aggregate logs from `com.coditory.sandbox.SomeClass` with message containing `[aggregate]` use following
configuration:
```xml
3000
[aggregate]
com.coditory.sandbox.SomeClass
```
Example:
```java
@Slf4j
class Sandbox {
public static void main(String[] args) throws InterruptedException {
log.info("Hello {}", "James");
log.info("[aggregate] Hello {}", "Mary");
log.info("[aggregate] Hello {}", "Mary");
log.info("[aggregate] Hello {}", "Mary");
log.info("Hello {}", "Mary");
log.info("Hello {}", "Mary");
Thread.sleep(5000);
}
}
// Output:
// 16:48:39.281 [main] INFO c.c.s.Sandbox - Hello James
// 16:48:39.284 [main] INFO c.c.s.Sandbox - Hello Mary
// 16:48:39.285 [main] INFO c.c.s.Sandbox - Hello Mary
// 16:48:42.248 [aggregating-filter-0-thread-0] INFO c.c.s.Sandbox - Hello Mary [occurrences=3]
```