Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osiegmar/logback-awslogs-json-encoder
Logback encoder for producing JSON formatted log output for Amazon CloudWatch Logs Insights
https://github.com/osiegmar/logback-awslogs-json-encoder
cloudwatch-logs logback
Last synced: 3 months ago
JSON representation
Logback encoder for producing JSON formatted log output for Amazon CloudWatch Logs Insights
- Host: GitHub
- URL: https://github.com/osiegmar/logback-awslogs-json-encoder
- Owner: osiegmar
- License: lgpl-2.1
- Created: 2018-12-09T09:13:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-10T05:43:01.000Z (about 1 year ago)
- Last Synced: 2024-10-09T20:50:28.973Z (3 months ago)
- Topics: cloudwatch-logs, logback
- Language: Java
- Homepage:
- Size: 276 KB
- Stars: 12
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Logback awslogs JSON encoder
[![build](https://github.com/osiegmar/logback-awslogs-json-encoder/actions/workflows/build.yml/badge.svg)](https://github.com/osiegmar/logback-awslogs-json-encoder/actions/workflows/build.yml)
[![javadoc](https://javadoc.io/badge2/de.siegmar/logback-awslogs-json-encoder/javadoc.svg)](https://javadoc.io/doc/de.siegmar/logback-awslogs-json-encoder)
[![Maven Central](https://img.shields.io/maven-central/v/de.siegmar/logback-awslogs-json-encoder.svg)](https://central.sonatype.com/artifact/de.siegmar/logback-awslogs-json-encoder)Logback encoder for producing JSON output that is handled by
AWS [CloudWatch Logs Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html). This
library has no external dependencies and thus very light footprint.Since version 1.3.8, Logback ships with a [JsonEncoder](https://logback.qos.ch/manual/encoders.html#JsonEncoder) itself.
Unfortunately that JsonEncoder produces log output that is poorly suited for use with CloudWatch Logs (Insights).## Features
- Forwarding of MDC (Mapped Diagnostic Context)
- Forwarding of caller data
- Forwarding of static fields
- Forwarding of exception root cause
- No runtime dependencies beside Logback## Requirements
- Java 11
- Logback 1.4.11## Prerequisites
Ensure that the task definition of your ECS task uses the `awslogs` log driver.
A full example (excerpt from a full task definition JSON) could look like this:
```json
{
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "myloggroup",
"awslogs-region": "eu-central-1"
}
}
}
```## Configuration
A basic configuration with defaults would look like this:
```xml
```
An extended version (with all default values set explicitly, custom static fields and mapper) would look like this:
```xml
true
false
false
true
true
true
true
false
true
false
true
true
true
falseapp_name:backend
os_arch:${os.arch}
```
## Example output
Typical output:
```json
{
"timestamp": 1698595093642,
"level": "DEBUG",
"thread": "Test worker",
"logger": "my.app.MyClass",
"message": "Message 1"
}
```Maximal output:
```json
{
"timestamp": 1698595093642,
"nanoseconds": 642725000,
"sequenceNumber": 0,
"level": "DEBUG",
"thread": "Test worker",
"logger": "my.app.MyClass",
"message": "Message 1",
"rawMessage": "Message {}",
"markers": {
"foo": 1,
"bar": 1
},
"mdc": {
"foo": "bar",
"baz": null
},
"keyValues": {
"foo": "bar",
"bar": null,
"null": "bar"
},
"caller": {
"file": "NativeMethodAccessorImpl.java",
"line": -2,
"class": "jdk.internal.reflect.NativeMethodAccessorImpl",
"method": "invoke0"
},
"stacktrace": "java.lang.IllegalStateException: Error processing data\n\tat my.app.MyClass.foo(MyClass.java:123)",
"rootCause": {
"class": "java.lang.IllegalStateException",
"message": "Error processing data"
},
"staticFields": {
"app_name": "backend",
"os_arch": "amd64"
},
"custom": "A field added by a custom mapper"
}
```