Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow override of "level" key's name in json log #12946

Closed
medvedev opened this issue Oct 26, 2020 · 6 comments
Closed

Allow override of "level" key's name in json log #12946

medvedev opened this issue Oct 26, 2020 · 6 comments
Labels
kind/enhancement New feature or request triage/wontfix This will not be worked on

Comments

@medvedev
Copy link
Contributor

medvedev commented Oct 26, 2020

Description
Problem: For Google Cloud Logging, every json entry is stored with "default" logging level no matter what level is used by an application. Reason is: the whole body of json entry is stored in Google Cloud Logging as a 2nd-level entry under "jsonPayload" key. This makes logs filtering a bit harder and makes harder or impossible to use GCP Error reporting
However, Google allows to set logging level by specifying "severity" key in log entry's json. Here's related stackoverflow question.

Enhancement: Allow to override default "level" name of log level field.
This is at least useful for Google Cloud Logging, where "severity" field in json is automatically recognized and moved to "top level" of logging entry.

Implementation ideas
Extension name: logging-json
I have at least 2 options in mind:

  1. Add new optional item to config of logging-json extension to override "level" key only
  2. Go more complex way and implement a solution that allows name overriding for any log key

I'll create a PR for option 1 very soon

@medvedev
Copy link
Contributor Author

There's already extension allowing override for "level" and much more other configurable options for json logging.
Here it is: https://github.com/quarkiverse/quarkiverse-logging-json
I'm closing this issue

@gsmet gsmet added the triage/wontfix This will not be worked on label Nov 5, 2020
@dratasich
Copy link

dratasich commented Jul 13, 2022

afaik, name or key overriding is now possible, see quarkus-logging-json config

For example, our ECS logging setup in Quarkus apps is:

quarkus:
  log:
    console:
      json:
        key-overrides: "timestamp=@timestamp,level=log.level,logger-name=log.logger,thread-name=process.thread.name,thread-id=process.thread.id,process-name=process.name,process-id=process.pid,stack-trace=error.stack_trace"
        excluded-keys: ["loggerClassName", "sequence", "hostName", "mdc", "ndc"]
        additional-field:
          service.name:
            value: "my-service-name"
            type: "string"

@medvedev
Copy link
Contributor Author

@dratasich great, thank you very much!
I didn't find any useful documentation about "quarkus.log.console.json.key-overrides" config.
Does it allow setting some values dynamically? Like, set "key-value" pair to a given log entry from my code?
In particular, I need it to integrate with GCP error reporting, which requires me to add a special field in order to make log entry "detected" as an error that should cause some kind of action.

@dratasich
Copy link

dratasich commented Jul 13, 2022

Hi @medvedev,
the config is for a JsonFormatter so the mappings and values are static. What you might looking for is a custom LogHandler (#6133 related?).
Regarding errors: error.stack_trace is added to the log message on exceptions.

@GinaGeorgescul
Copy link

afaik, name or key overriding is now possible, see quarkus-logging-json config

For example, our ECS logging setup in Quarkus apps is:

quarkus:
  log:
    console:
      json:
        key-overrides: "timestamp=@timestamp,level=log.level,logger-name=log.logger,thread-name=process.thread.name,thread-id=process.thread.id,process-name=process.name,process-id=process.pid,stack-trace=error.stack_trace"
        excluded-keys: ["loggerClassName", "sequence", "hostName", "mdc", "ndc"]
        additional-field:
          service.name:
            value: "my-service-name"
            type: "string"

Hey,
I have been trying to use this approach in my application.properties file:

quarkus.log.console.json.excluded-keys=["loggerClassName", "sequence", "hostName", "ndc", "processId", "processName", "threadId"]
quarkus.log.console.json.key-overrides="threadName=thread.name, level=log.level, loggerName=logger.name"

For the key overrides I get
Failed to start application (with profile [dev]): java.lang.IllegalArgumentException: No enum constant org.jboss.logmanager.formatters.StructuredFormatter.Key."THREADNAME
If I only try to exclude keys, none are excluded.

Is there something I'm doing wrong?

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-logging-json</artifactId>
    </dependency>

Quarkus version is 2.16.1.

Any help would be appreciated, thank you !

@dratasich
Copy link

dratasich commented Nov 3, 2023

As pointed out in #36133, the config format/syntax changed for the string arrays:

quarkus.log.console.json.excluded-keys=loggerClassName,sequence,hostName,mdc,ndc
quarkus.log.console.json.key-overrides=timestamp=@timestamp,level=log.level,logger-name=log.logger,thread-name=process.thread.name,thread-id=process.thread.id,process-name=process.name,process-id=process.pid,stack-trace=error.stack_trace

Thanks @ozangunalp and @GinaGeorgescul :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request triage/wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants