Giter Site home page Giter Site logo

quarkus-logging-json's Introduction

Maven Central Sonar Coverage

All 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

Elastic Common Scheme

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.

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

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:

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


Simon Bengtsson

๐Ÿ’ป ๐Ÿšง

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.