Skip to content

Using ContextualLogging with GELF #49

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

Closed
Podnevar opened this issue Jul 19, 2022 · 3 comments
Closed

Using ContextualLogging with GELF #49

Podnevar opened this issue Jul 19, 2022 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@Podnevar
Copy link

Podnevar commented Jul 19, 2022

I'm trying to use contextual logging with Graylog (GELF). The problem i'm having and can't figure it out is how to send this additional fields that I added to context logs. Logging works ok, I see logs on Graylog just no additional fields like it showed with MDC.

What I tried is to use custom ContextDataProvider with creating file under META-INF/services org.apache.logging.log4j.core.util.ContextDataProvider and inserting then io.reactiverse.contextual.logging.VertxContextDataProvider

My log4j2.xml:
<Configuration> <Appenders> <Socket name="GELF" protocol="tcp" host="my.url" port="9850"> <GelfLayout includeStackTrace="true" includeThreadContext="true" includeNullDelimiter="true" compressionType="OFF"> </GelfLayout> </Socket> </Appenders> <Loggers> <Root level="INFO"> <AppenderRef ref="GELF" /> </Root> </Loggers> </Configuration>

How much I tried to debug it seems log4j doesen't pickup this VertxContextDataProvider, could I miss something when creating this file? Is type wrong or what it could be?

@tsegismont
Copy link
Contributor

Can you share a small reproducer project please?

@tsegismont tsegismont self-assigned this Aug 1, 2022
@Podnevar
Copy link
Author

Podnevar commented Aug 2, 2022

Can you share a small reproducer project please?

Here is the recreation of the problem:
https://github.com/Podnevar/contextual-logging-log4j-reactive

@tsegismont tsegismont added bug Something isn't working question Further information is requested and removed bug Something isn't working labels Nov 18, 2022
@tsegismont
Copy link
Contributor

Sorry for the long delay. I ran socat to simumate GELF target:

socat TCP-LISTEN:9850,reuseaddr,fork STDOUT

Then I changed this in the log4j2 config because the syntax for context map lookup was wrong in console:

Index: src/main/resources/log4j2.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
--- a/src/main/resources/log4j2.xml	(revision cd29bd79158f6973bafb91db2c79e2c290ecea07)
+++ b/src/main/resources/log4j2.xml	(date 1669042713667)
@@ -10,7 +10,7 @@
 
         <Console name="Console" target="SYSTEM_OUT">
             <PatternLayout>
-                <pattern>%d{HH:mm:ss.SSS} [%thread] [%vcl{requestId}] %-5level %logger{36} - %msg%n</pattern>
+                <pattern>%d{HH:mm:ss.SSS} [%thread] [$${ctx:requestId:-foobar}] %-5level %logger{36} - %msg%n</pattern>
             </PatternLayout>
         </Console>
 
@@ -40,6 +40,7 @@
         </Logger>
         <Root level="INFO">
             <AppenderRef ref="GELF" />
+            <AppenderRef ref="Console" />
         </Root>
     </Loggers>
 </Configuration>

Then I ran the app. In dev mode, indeed the contextual data is not added to the log events (neither to the console or to GELF target). However, if I build the application and then run it:

mvn clean package
java -jar target/quarkus-app/quarkus-run.jar 

Then the contextual data is present in both the console and GELF json message.

So I suspect this is a classloading issue due to the Quarkus dev mode, unrelated to this library.

@tsegismont tsegismont closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants