Comments (7)
Hey @mschwehl, I am glad you liked the project. Though I am a bit confused by your questions. Let me elaborate that a bit:
- Judging by logback-spring.xml you shared,
spring-cloud-samples
uses Logback for logging, though, as its name implies,log4j2-logstash-layout
is a Log4j 2.x layout plugin. So I am totally puzzled here. That being said, I will address your questions assuming you want to use Log4j 2.x in combination withlog4j2-logstash-layout
plugin inspring-cloud-examples
. - You want to expose pid. I think what you need is to just add a
pid
attribute referencing to${env:PID}
. Just create a new template JSON having"pid": "${env:PID}"
and you are done. (Why can't we ship it by default? Because we stick to JSONEventLayoutV1, which has a pre-defined structure.) - We are using the default Jackson
ObjectMapper
to read and write JSON. So you want to configure this mapper, say, to emit empty string onnull
entries. Correct?
from log4j2-logstash-layout.
Hello @vy,
Thank you for your quick response and sorry for the confusion here.
My office is using an infrastructure using elkstack. One huge client is sending json messages in the 'sleuth' format and i want to produce the same output for my client using your log4j-json library
All works fine so far, thank you for providing this lib, it really fills a gap.
Refering to 2:
My tester is
MDC.put("X-B3-TraceId", "tracID");
logger.info("Test Message");
// pattern.json
{
"message": "${json:message}",
"severity": "${json:level}",
"trace": "${json:mdc:X-B3-TraceId}",
"nulltest": "${json:mdc:nulltest}",
"pid": "${env:PID}"
}
//output
{"message":"Test Message","severity":"INFO","trace":"tracID","nulltest":"null","pid":"${env:PID}"}
i think the PID is not evaluated, therefore my question i asked to you
Refering to 3:
I will have a look how to achieve the translation from 'null' to "" in nulltest using jackson.
best regards
Martin.
from log4j2-logstash-layout.
There was indeed a bug with resolving null
MDC (context data) values. I pushed the fix. Would you mind testing it, please? If it works for you, I will make a new release.
Coming back to the PID discussion... I thought you already had an environment variable called PID
passed to your Java application. My suggestion is to first retrieve the PID in Java and then call System.setProperty("PID", pid)
, which will make it accessible to Log4j lookups with ${env:PID}
variable.
from log4j2-logstash-layout.
I can confirm that the null-issue is fixed, thank you
Back to PID. It was my misanderstanding, i was thinking that
is providing the pid just like the ThreadId. I was wrong, thank you for pointing me to my error.
There are several ways to put the pid in the MDC. I will choose one of them and can go on with my coding. If you don't mind i will close this issue after your next release (or you can do as well)
Bist wishes
Martin
from log4j2-logstash-layout.
@mschwehl, great! Thanks for taking time to test it. I have just pushed the new release to Sonatype. v0.11 should appear in Maven Central momentarily.
from log4j2-logstash-layout.
Is it possible to get PID without manipulating MDC? We have got an application which we cannot modify, but we have got access to log4j2.xml. Thank you.
from log4j2-logstash-layout.
Using LogstashLayout
, you can have the PID as follows:
- Put the PID into an environment variable, e.g.,
PID
. - Configure
LogstashLayout
as follows:
<LogstashLayout ...>
<EventTemplateAdditionalFields>
<KeyValuePair key="pid" value="${env:PID}"/>
</EventTemplateAdditionalFields>
</LogstashLayout>
If you can use JsonTemplateLayout
instead, which I strongly recommend you to do, you can solve this without introducing any environment variables:
<JsonTemplateLayout eventTemplateUri="classpath:GelfLayout.json">
<EventTemplateAdditionalField
key="pid"
format="JSON"
value='{"$resolver": "pattern", "pattern": "%pid"}'/>
</JsonTemplateLayout>
from log4j2-logstash-layout.
Related Issues (20)
- BufferOverflowException get thrown for messages of a larger size HOT 7
- LogstashLayout with log4j2-elasticsearch appender HOT 1
- Introduce properties to globally set LogstashLayout.Builder defaults
- Nullpointer exceptions at LogstashLayoutSerializationContexts$StringTruncatingGeneratorDelegate HOT 1
- Any template ready for GCP? HOT 9
- Message lost if exceeding maxStringLength and emptyPropertyExclusionEnabled is true HOT 4
- Use ByteArrayOutputStream instead of ByteBufferOutputStream to avoid message loss HOT 8
- Stacktraces larger than maxStringLength are not truncated HOT 7
- Failed serializing JSON: BufferOverflowException HOT 10
- How to output ThreadContext (ex -MDC fields) HOT 1
- Review request for Log4j JsonTemplateLayout HOT 7
- How exactly is MapMessage supposed to be handled? HOT 7
- Multiple template variables in single property lead to an exception HOT 2
- Fallback for json:map: fields for libraries HOT 1
- NoClassDefFoundError: logstash.layout.resolver.TemplateResolvers (initialization failure) HOT 1
- Remove max byte count cap? HOT 1
- Reference whole MapMessage - and not just keys HOT 13
- Compiling with JDK 8 results in java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer; HOT 4
- Marker lookup subsitutes literal string when marker not available HOT 1
- BufferOverflowException occurs intermittently when sending data via socket appender HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log4j2-logstash-layout.