quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Named handlers for a category in gelf not supported

Open blsouthr opened this issue 4 years ago • 10 comments

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

  • Output of uname -a or ver: Windows
  • Output of java -version: openjdk version "11" 2018-09-25
  • Quarkus version or git rev: 1.3.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): 3.6.3

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

blsouthr avatar Apr 22 '20 09:04 blsouthr

/cc @loicmathieu

gsmet avatar Apr 22 '20 11:04 gsmet

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 ...

loicmathieu avatar Apr 22 '20 12:04 loicmathieu

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

blsouthr avatar Apr 22 '20 13:04 blsouthr

@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.

loicmathieu avatar Apr 23 '20 07:04 loicmathieu

@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 avatar Apr 23 '20 07:04 blsouthr

@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

blsouthr avatar May 04 '20 10:05 blsouthr

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

loicmathieu avatar May 04 '20 10:05 loicmathieu

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

blsouthr avatar May 04 '20 11:05 blsouthr

Hello guys, is there any update in this issue?

carlos-m-rodrigues avatar Sep 03 '21 13:09 carlos-m-rodrigues

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.

therrewi avatar Aug 10 '22 14:08 therrewi