gravitee-io / issues

Gravitee.io - API Platform - Issues
64 stars 26 forks source link

[gateway] Add the libraries to allow to write application logs in JSON by changing the logback configuration #5139

Closed aelamrani closed 3 years ago

aelamrani commented 3 years ago

We should add in the node the libraries useful to log in JSON:

The goal is to be able to log in JSON by changing the logback config with:

     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
                <timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSSX</timestampFormat>
                <timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>

                <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
                    <prettyPrint>false</prettyPrint>
                </jsonFormatter>
                <appendLineSeparator>true</appendLineSeparator>
            </layout>
        </encoder>
    </appender>

Flat result:

{"timestamp":"2020-05-26T11:17:51.678Z","level":"INFO","thread":"graviteeio-node","logger":"io.gravitee.node.container.spring.env.PropertiesConfiguration","message":"Loading Gravitee configuration.","context":"default"}
{"timestamp":"2020-05-26T11:17:51.686Z","level":"INFO","thread":"graviteeio-node","logger":"io.gravitee.node.container.spring.env.PropertiesConfiguration","message":"\tGravitee configuration loaded from /Users/azize/tools/graviteeio-full/graviteeio-gateway-3.0.0/config/gravitee.yml","context":"default"}
{"timestamp":"2020-05-26T11:17:51.745Z","level":"INFO","thread":"graviteeio-node","logger":"io.gravitee.node.container.spring.env.PropertiesConfiguration","message":"Loading Gravitee configuration. DONE","context":"default"}

Pretty print:

{
  "timestamp" : "2020-05-26T11:20:57.098Z",
  "level" : "INFO",
  "thread" : "graviteeio-node",
  "logger" : "io.gravitee.node.container.spring.env.PropertiesConfiguration",
  "message" : "Loading Gravitee configuration.",
  "context" : "default"
}
{
  "timestamp" : "2020-05-26T11:20:57.105Z",
  "level" : "INFO",
  "thread" : "graviteeio-node",
  "logger" : "io.gravitee.node.container.spring.env.PropertiesConfiguration",
  "message" : "\tGravitee configuration loaded from /Users/azize/tools/graviteeio-full/graviteeio-gateway-3.0.0/config/gravitee.yml",
  "context" : "default"
}
AnthonyTissot commented 1 year ago

hi could be great to add this great feature in your documentation. or i have missed it ?