Comments (13)
@mobby38 You can use ThreadContext
as decribed here
from log4j2-elasticsearch.
Yes, but how you can do that without modifying the existing code.
The proof of concept I'm trying to achieve is to replace filebeat with just a log4j2 appender, but it misses those data, and I can't modify the code of the application.
What I could do is to provide Environment properties and give it to Log4j2 via the configuration.
Is there a way to do so?
from log4j2-elasticsearch.
You can do that using configuration. Just switch to Log4j2 JsonLayout
and do that with KeyValuePair
s and env variables. You'll sacrifice the ability to use object pooling and customisable output though. Plus, you'll need to specify a new date column in your mappings as default set of mixins in JsonLayout
serialize LogEvent a bit differently.
I'll add support for KeyValuePair
s in JacksonJsonLayout
in 1.4.
from log4j2-elasticsearch.
Thanks :)
from log4j2-elasticsearch.
In my opinion, you should also remove jsonIgnore in LogEventJacksonJsonMixIn and avoid renaming threadName by thread.
Just let the trick on timeMillis.
It tooks me some times to understand why not all attribute (including context) was hidden in the Json message.
from log4j2-elasticsearch.
Good point on the contextData
. There's a lot of confusion over this Log4j2 feature and I think I've gone too far while making the LogEvent 'thinner'.
Thankfully, you can augment any part of the output quite easily with JacksonMixIn
.
from log4j2-elasticsearch.
Is 1.4 coming? Just thinking whether to wait for VirtualProperty or try to use KeyValuePair
from log4j2-elasticsearch.
Yes. 1.4 should be out soon. It got heavily delayed due to FileBackedRetryFailoverPolicy
work - sorry for that..
from log4j2-elasticsearch.
Could you add an example of JsonLayout to docs? Simply replacing JacksonJsonLayout with JsonLayout doesn't error out but doesn't push anything to Elastic either, was wondering whether I missed something.
from log4j2-elasticsearch.
@ricsil Sure, will do. Could you post your updated configuration in the meantime?
from log4j2-elasticsearch.
So, this works fine (mix-in is there for timestamp override)
<Elasticsearch name="elasticsearchAsyncBatch">
<RollingIndexName indexName="test-log-app" pattern="yyyy-MM-dd" />
<JacksonJsonLayout>
<JacksonMixIn mixInClass="path.to.utils.CustomLogEventMixIn"
targetClass="org.apache.logging.log4j.core.LogEvent"/>
</JacksonJsonLayout>
<AsyncBatchDelivery>
<JestHttp serverUris="http://elastic-server:9200" />
</AsyncBatchDelivery>
</Elasticsearch>
Replacing JacksonJson with Json doesn't produce anything
<Elasticsearch name="elasticsearchAsyncBatch">
<RollingIndexName indexName="test-log-app" pattern="yyyy-MM-dd" />
<JsonLayout />
<AsyncBatchDelivery>
<JestHttp serverUris="http://elastic-server:9200" />
</AsyncBatchDelivery>
</Elasticsearch>
On the other hand, replacing JacksonJsonLayout with EcsLayout (not forgetting to add dependency) works fine:
<Elasticsearch name="elasticsearchAsyncBatch">
<RollingIndexName indexName="test-log-app" pattern="yyyy-MM-dd" />
<EcsLayout />
<AsyncBatchDelivery>
<JestHttp serverUris="http://elastic-server:9200" />
</AsyncBatchDelivery>
</Elasticsearch>
https://github.com/elastic/ecs-logging-java/tree/master/log4j2-ecs-layout
Also, EcsLayout supports KeyValuePair in case someone needs it.
from log4j2-elasticsearch.
@ricsil you need
<JsonLayout compact="true"/>
cause default one prints pretty JSON. Have a look and updated docs
from log4j2-elasticsearch.
VirtualProperty
support released in 1.4.
from log4j2-elasticsearch.
Related Issues (20)
- Supporting ecs-logging-java HOT 8
- Package naming conventions HOT 11
- How to pass the value from ThreadContext to ValueProperty? HOT 3
- Can not log to elastic using log4j2 <PatternLayout> HOT 11
- Support elasticsearch data_streams HOT 6
- Failed to Load StackTraceElementMixIn HOT 22
- InvalidTypeNameException on invalid mappingType in ES 5 HOT 8
- Adding custom properties, that change during processing HOT 4
- Log4j2 Zero-Day vulnerability (CVE-2021-44228) HOT 2
- Support OpenSearch 2.x and Elasticsearch 8.x HOT 9
- Unable to determine if index already exists HOT 1
- Support for ECSLayout for elasticsearch-ahc and / or elaticsearch-jest in combination with data streams HOT 10
- Is it possible to deseriailze JSON within the message into properties? HOT 2
- Run elastic search appender in specific environment HOT 2
- Logging-Cleaner ERROR Could not create plugin HOT 3
- How do I add mdc attributes? HOT 1
- Could not initialize ChronicleMapRetryFailoverPolicy HOT 2
- ServiceDiscovery ERROR HCServiceDiscovery: Unable to refresh addresses: Cannot invoke "org.appenders.log4j2.elasticsearch.hc.discovery.NodeInfo$PublishAddress.getPublishAddress()" HOT 1
- Using log4j2-elasticsearch-hc -> Does AsyncLogger still not support adding dynamic keyValue pairs in Jackson JSONLayout HOT 5
- IS JacksonModule is implemented in latest version? HOT 7
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-elasticsearch.