Skip to content

lthasle/quarkus-logging-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

All Contributors

Quarkiverse Logging Json

Quarkus logging extension outputting the logging in json.

Configuration

The extension is enabled by default, when added to the project. Can be disabled using configuration: quarkus.log.console.json=false

To see additional configuration options take a look at Config

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.

quarkus.log.console.json.additional-field.serviceName.value=service-a
# type is by default STRING - Other is INT, LONG, FLOAT, DOUBLE 
quarkus.log.console.json.additional-field.buildNumber.type=INT
quarkus.log.console.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.quarkus.logging.json.structured.StructuredArgument. Then it is possible to use the JsonGenerator to format the argument in json.

Simple usage

import static io.quarkus.logging.json.structured.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:

import javax.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 {

    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):


Simon Bengtsson

💻 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Quarkus logging extension outputting the logging in json.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%