Quarkus logging extension outputting the logging in json.
Quarkus Version | Use version |
---|---|
3.x.x | 3.x.x |
2.x.x | 1.x.x, 2.x.x |
The extension is enabled by default for console, when added to the project.
Console logging can be disabled using configuration: quarkus.log.json.console.enabled=false
To see additional configuration options take a look at Config
quarkus.log.json.log-format=ecs
If you want to add a static field to all the log message, that is possible using the configuration.
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
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.
import static io.quarkiverse.loggingjson.providers.KeyValueStructuredArgument.*;
...
log.info("Test log of structured arg", kv("key", "value"));
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:
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.
}
}
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).
Thanks goes to these wonderful people (emoji key):
Simon Bengtsson 💻 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!
`