Comments (5)
I tried to add VirtualProperty with no luck:
<Elasticsearch name="elasticsearch">
<IndexName indexName="XXX"/>
<ThresholdFilter level="DEBUG" onMatch="ACCEPT"/>
<JacksonJsonLayout>
<NonEmptyFilter/>
<VirtualProperty name="field1" value="$${ctx:ctxVariable:-}" dynamic="true" />
<PooledItemSourceFactory poolName="itemPool" itemSizeInBytes="1024" initialPoolSize="3000"/>
</JacksonJsonLayout>
<AsyncBatchDelivery batchSize="1" deliveryInterval="2" >
<IndexTemplate name="XXXX" path="classpath:indexTemplate.json" />
<HCHttp serverUris="http://XXXX:9200">
<PooledItemSourceFactory poolName="batchPool" itemSizeInBytes="1024000" initialPoolSize="3"/>
</HCHttp>
</AsyncBatchDelivery>
</Elasticsearch>
and changed the logger to log:
logger.atError().addKeyValue("field1", authenticationRequest).addKeyValue("test","value").log("11111111111111111");
and still field1 is not present as a seperated field
from log4j2-elasticsearch.
Hi @morad3741
If you're trying to resolve $${ctx:ctxVariable:-}
, then ctxVariable
is the one that must be resolvable within LogEvent.contextData. field1
is just it's name in the output document.
Try this:
logger.atError().addKeyValue("ctxVariable", "33333")
from log4j2-elasticsearch.
Hi,
Im trying to add new field to the JSON dynamically,
Just like it shown in the next guide: logback logstash guide
in their example:
log.info("Order saved", kv("orderId", orderId), kv("status", status));
will create "orederId" and "status" node in the JSON,
Im looking for a way to do the same in log4j.
I tried:
logger.atError().addKeyValue("ctxVariable", "33333")
it didnt added anything to the JSON,
Thanks for your help
from log4j2-elasticsearch.
My mistake. I assumed that SLF4j2 .addKeyValue
works like MDC. It turns out that it doesn't.
According to SLF4J Manual, addKeyValue
will just help you log like this:
int newT = 15;
int oldT = 16;
// using classical API
logger.debug("oldT={} newT={} Temperature changed.", newT, oldT);
// using fluent API
logger.atDebug().addKeyValue("oldT", oldT).addKeyValue("newT", newT).log("Temperature changed.");
to get the same output as DefaultLoggingEventBuilder#mergeMarkersAndKeyValuePairs
in slf4j-api:2.0.0-alpha1 will just prepend the keys as it used to in old versions.
In order to get the behaviour you expect, you need MDC:
MDC.put("ctxVariable", "someValue");
logger.atError().log("11111111111111111");
MDC.remove("ctxVariable");
It will work only with synchronous loggers.
If you need to use asynchronous loggers, you'll can get MDC to work as expected by overriding LogEvent.contextData serialization with Jackson mix-in as described here.
from log4j2-elasticsearch.
Closing due to lack of activity
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.