-
Notifications
You must be signed in to change notification settings - Fork 34
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
Without MDC, KeyValuePair Cannot be Used #27
Comments
Did you ever find a way around this @coderlol ? |
Has this ever worked? You don't construct your own Log4jEvent and LogEventToLogStashLogEventConverter never gets used. |
It's used in the jackson serializer mixin |
@StephenGoodall, I think. Don't recall exactly what I did, but let's see if I can zip it all up and send it |
Thanks @coderlol that would be great, I've been trying to use a ruby filter to convert log4j2's json event into "standard" json but this would be much neater |
@majikthys My mistake, LogEventToLogStashLogEventConverter is getting used. But additionalLogAttributes never get inserted into contextMap since like @coderlol mentioned Log4jLogEvent constructor initializes it like: That is why LogStashJSONLayout.toSerializable throws java.lang.UnsupportedOperationException and short of using custom LogEventFactory I don't know how to use this otherwise very beautiful piece of code. |
In what circumstance is MDC of LogEvent null? I've added branch issue/27 with a proposed solution, please comment. https://github.com/majikthys/log4j2-logstash-jsonevent-layout/tree/issue/27 |
If it helps, I wrote this as a quick test:
This gives the following output in the log file:
That was using this config:
So i think it seems to work for the first line because at that point there is no MDC specified. So it outputs it to the log file, the rest of the time it fails to write to the log. Not sure why it doesn't try for the last 5 attempts though. I'll try and build your latest version (issue 27) and see if it fixes the issue :) |
I might not be doing it right but it failed with an error:
I think it may be due to this line (166):
Should it be:
I changed it to the above and it seemed to build. Will try and use the jar now |
I got this stacktrace:
So changed LogStashLogEvent.java:125 to be:
This allowed it to run, but it threw the new error, and this stack trace again:
Hopefully this is helpful.........i hope I haven't confused anything. Let me know if you want me to run some other tests or if I've done these wrong. |
Hi @majikthys, is there any news on this? Did the tests I ran help at all? Happy to run some more if needed 😃 |
@StephenGoodall go ahead and review 7dccf46 on branch https://github.com/majikthys/log4j2-logstash-jsonevent-layout/tree/issue/27-redux and let me know if that is a suitable approach. |
@majikthys I get this error: But when I change it to getTimeMillis() it seems to work but the MDC/contextMap doesn't get printed in the log file. I added this as the config:
and the hostname key:value pair wasn't printed in the logs either, here is an example of a log event in the log file:
This is my log4j2.xml file:
Am I missing something from the config? |
@StephenGoodall were you able to resolve the map issue? I am having same issue at my end. |
Hi @osmancis |
Hi @StephenGoodall Thanks for quick response. I was able to get around this issue by not using the overriden getContext (Meaning commenting it out) and add
|
Hi @osmancis was that inside the LogStashLogEvent class? I can see an overridden getContextMap but not getContext. cheers |
hi @StephenGoodall , were you able to put the MDC value in you json log? |
Hi @buddhashrestha not yet, I haven't had any time to try it out recently. |
Hi @StephenGoodall , This version is compiled with log4j2 2.5, check the version of log4j2 in your project. I've got the same kind of issue due to my 2.3 version of log4j2 |
You can use this https://github.com/Diallos/logging-event-layout It works for log4j, log4j2 and logback. |
Is there any way to make changes to context map in code (say - to rewrite a key value pair) |
crikes, this has bitten us as well. |
If no MDC is supplied and KeyValuePair is used, this is the error. I think it is due to the use of emptyMap() which is immutable.
Gradle suite > Gradle test > org.apache.logging.log4j.core.layout.LogStashJSONLayoutJacksonIT.BasicSimpleTest FAILED
java.lang.UnsupportedOperationException
at java.util.AbstractMap.put(AbstractMap.java:209)
at java.util.AbstractMap.putAll(AbstractMap.java:281)
at org.apache.logging.log4j.core.layout.LogStashJSONLayout.toSerializable(LogStashJSONLayout.java:189)
at org.apache.logging.log4j.core.layout.LogStashJSONLayoutJacksonIT.BasicSimpleTest(LogStashJSONLayoutJacksonIT.java:101)
The text was updated successfully, but these errors were encountered: