Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/quarkiverse/quarkus-logging-json

Quarkus logging extension outputting the logging in json.
https://github.com/quarkiverse/quarkus-logging-json

hacktoberfest json logging quarkus quarkus-extension

Last synced: 2 days ago
JSON representation

Quarkus logging extension outputting the logging in json.

Awesome Lists containing this project

README

        

[![Maven Central](https://img.shields.io/maven-central/v/io.quarkiverse.loggingjson/quarkus-logging-json?logo=apache-maven&style=for-the-badge)](https://search.maven.org/artifact/io.quarkiverse.loggingjson/quarkus-logging-json)
[![Sonar Coverage](https://img.shields.io/sonar/coverage/quarkiverse_quarkus-logging-json?logo=sonarcloud&server=https%3A%2F%2Fsonarcloud.io&style=for-the-badge)](https://sonarcloud.io/dashboard?id=quarkiverse_quarkus-logging-json)

[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)

# Quarkus Logging Json
Quarkus logging extension outputting the logging in json.

## Version to use
| Quarkus Version | Use version |
|-------|-------|
| 3.x.x | 3.x.x |
| 2.x.x | 1.x.x, 2.x.x |

# Configuration
The extension is enabled by default for console, when added to the project.
Console logging can be disabled using configuration: `quarkus.log.json.console.enable=false`

To see additional configuration options take a look at [Config](https://quarkiverse.github.io/quarkiverse-docs/quarkus-logging-json/dev/index.html)

## Elastic Common Scheme
```properties
quarkus.log.json.log-format=ecs
```

# Add additional fields to all log messages
If you want to add a static field to all the log message, that is possible using the configuration.
```properties
quarkus.log.json.additional-field.serviceName.value=service-a
# type is by default STRING - Other is INT, LONG, FLOAT, DOUBLE
quarkus.log.json.additional-field.buildNumber.type=INT
quarkus.log.json.additional-field.buildNumber.value=42
```

# Structured argument
If you want to do structured logging of arguments, then the argument send with your logging, can implement `io.quarkiverse.loggingjson.providers.StructuredArgument`. Then it is possible to use the JsonGenerator to format the argument in json.

## Simple usage
```java
import static io.quarkiverse.loggingjson.providers.KeyValueStructuredArgument.*;
...
log.info("Test log of structured arg", kv("key", "value"));
```
# Custom log handler
If you want to add your own custom way to handle the LogRecords.
You can create your own implementations of `io.quarkiverse.loggingjson.JsonProvider`, and provide it using CDI.
Example implementation:
```java
import jakarta.inject.Singleton;
import java.io.IOException;

import io.quarkiverse.loggingjson.JsonProvider;
import io.quarkiverse.loggingjson.JsonGenerator;
import org.jboss.logmanager.ExtLogRecord;

@Singleton
public class MyJsonProvider implements JsonProvider {

@Override
public void writeTo(JsonGenerator generator, ExtLogRecord event) throws IOException {
generator.writeStringField("myCustomField", "and my custom value"); // Will be added to every log, as a field on the json.
}
}
```

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Simon Bengtsson

💻 🚧

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!