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: 3 months ago
JSON representation
Quarkus logging extension outputting the logging in json.
- Host: GitHub
- URL: https://github.com/quarkiverse/quarkus-logging-json
- Owner: quarkiverse
- License: apache-2.0
- Created: 2020-10-01T12:54:47.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2026-03-18T21:14:00.000Z (4 months ago)
- Last Synced: 2026-03-19T08:50:03.546Z (4 months ago)
- Topics: hacktoberfest, json, logging, quarkus, quarkus-extension
- Language: Java
- Homepage:
- Size: 461 KB
- Stars: 81
- Watchers: 4
- Forks: 36
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://search.maven.org/artifact/io.quarkiverse.loggingjson/quarkus-logging-json)
[](https://sonarcloud.io/dashboard?id=quarkiverse_quarkus-logging-json)
[](#contributors-)
# Quarkus Logging JSON
Quarkus logging extension outputting the log messages in JSON.
It supports the following formats: default, [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs-logging/overview/current/intro.html).
## 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 and socket, when added to the project.
Console json logging can be disabled using configuration: `quarkus.log.json.console.enabled=false`
Socket json logging can be disabled using configuration: `quarkus.log.json.socket.enabled=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.
}
}
```
## Fully customized json output without providers (`log-format=none`)
Sometimes there is a need for a fully customized json output (e.g. for support of corporate json log format): The usual adjustment methods of the log output are not sufficient, if some of the existing providers are needed to be moved down the json object tree to some subobject inside attributes (e.g. put the message inside a json `data` object `data.message`).
In such cases the idea is to start with an empty format by adding
```properties
quarkus.log.json.log-format=none
```
to the configuration. This format doesn't add any fields to the json output and ignores any field specific configuration. Next you need to implement the full json output yourself, by writing a custom `JsonProvider` implementation (here putting the message inside the `data` object):
```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 FullyCustomizedJsonProvider implements JsonProvider {
@Override
public void writeTo(JsonGenerator generator, ExtLogRecord event) throws IOException {
generator.writeObjectField("data", Map.of("message", event.getMessage())); // outputs the message inside a data object
}
}
```
In the above example, the `message` is just written plain, see `MessageJsonProvider` for an example on how to write the message formatted for being written into json.
## Configuration Properties Relocation
In 3.2.0, two configuration properties were renamed to be more consistent with Quarkus configuration.
- Old: `quarkus.log.json.console.enable` → New: `quarkus.log.json.console.enabled`
- Old: `quarkus.log.json.file.enable` → New: `quarkus.log.json.file.enabled`
A relocation/fallback mechanism has been added so the old properties are still supported
but we recomment that you switch to the new ones
(`quarkus update` will do it for you).
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
`