quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.57k stars 2.63k forks source link

Named handlers for a category in gelf not supported #8742

Open blsouthr opened 4 years ago

blsouthr commented 4 years ago

Describe the bug According to quarkus documentation, named handlers can be added and attached to categories: https://quarkus.io/guides/logging#category-example

It is not supported with gelf however.

Expected behavior custom handlers should be supported with their own configs like additional fields.

Actual behavior Configuration produces a warning at startup

Unrecognized configuration key "quarkus.log.handler.gelf."CUSTOM".additional-field.addfield.value" was provided; it will be ignored Unrecognized configuration key "quarkus.log.handler.gelf."CUSTOM".enable" was provided; it will be ignored

To Reproduce Steps to reproduce the behavior:

  1. Add regular gelf config and the following: quarkus.log.handler.gelf."CUSTOM".enable=true quarkus.log.handler.gelf."CUSTOM".additional-field.addfield.value=custom quarkus.log.category."com.io.filter.FilteredLogger".handlers=CUSTOM

  2. start the app, the warning is logged

Environment (please complete the following information):

Additional context The goal is that some loggers (categories) can add and overwrite GELFs additional fields.

gsmet commented 4 years ago

/cc @loicmathieu

loicmathieu commented 4 years ago

Named handlers are supported on standard handlers (the one incuded in the core quarkus library) but not in the logging-gelf extension.

So this is a feature request not a bug, be careful that behind each GELF handler there is a socket to write to a server so I'm not sure it's a good idead to create multiple ones ...

blsouthr commented 4 years ago

Agree. Was not clear from documentation. I'm aware of separate sockets, but how else could we overwrite additional fields per category?

loicmathieu commented 4 years ago

@blsouthr another solution would be to use MDC fields (https://logging.paluch.biz/mdc.html) but these are not currently exposed inside the logging-gelf extension.

blsouthr commented 4 years ago

@loicmathieu Maybe some kind of filtering could be applied, so that filter given the log category could add/override additional fields. Something like:

quarkus.log.handler.gelf.filter."com.company.SomeClass".additional-field.addfield.fieldname=fieldvalue

that way no extra appender/socket would be needed

blsouthr commented 4 years ago

@loicmathieu I've implemented overriding of additional fields by extending JBoss7GelfLogHandler and overriding createGelfMessage method. Based on config it can then put additional values only for configured loggers E.g.

quarkus.log.handler.gelf.additional-filter."com.comp.SomeClass".fieldname.value=fieldvalue

It works for me, but I guess, you'd probably want to change config format

See gelf.zip

loicmathieu commented 4 years ago

@blsouthr MDC is a standard logging mechanism, could it be used if we expose them ?

blsouthr commented 4 years ago

@loicmathieu I don't think so. Or, I don't know how MDC could help to achieve what I want

carlos-m-rodrigues commented 3 years ago

Hello guys, is there any update in this issue?

therrewi commented 2 years ago

It would be great to be able to attach a category to the gelf logger. In the Wildfly Keycloak version we are using the socket logger to send the "org.keycloak.events" messages to logstash for audit logging. If it would be possible to send a certain category to logstash the functionality would be the same.