You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You might be wondering , why would i use PatternLayout in the elastic appender , but the main reason for that is because I am using custom messages whenever I'm logging to escape log4j2 inserted metadata in the log message. Everything is working just fine with such configuration for elastic appender. A little bit later I decided to use HCHttp client instead of Jest client because it was mentioned in documentation , that it is more optimized. Here is configuration of appender:
<Elasticsearch name="SERVICE_LOGS_ELASTICSEARCH"> <IndexName indexName="java-service-${bundle:application:info.build.archiveBaseName}"/> <PatternLayout pattern="%m%n"/> <AsyncBatchDelivery batchSize="1000" deliveryInterval="5000"> <HCHttp serverUris="${bundle:application:spring.elasticsearch.jest.uris}"> <PooledItemSourceFactory poolName="batchPool" itemSizeInBytes="1024000" initialPoolSize="3"/> </HCHttp> </AsyncBatchDelivery> </Elasticsearch>
So , this configuration would not wrok , throwing java.lang.UnsupportedOperationException: Use ItemSource based API instead.
Here is the my app link , if you wonder about what I am trying to achieve : https://github.com/jafarjafarov/actuatorSwaggerCRUDSample. The main idea is to allow the exposure of different java objects in elastic in json format during some flow execution.
Thanks in advance
The text was updated successfully, but these errors were encountered:
If you'd like to use HCHttp to get the optimizations, JacksonJsonLayout is the only out-of-the-box layout that you can use. Otherwise, you have to implement your own ItemSourceLayout.
ItemSource API is a part of the optimization here - in this case, it provides a bunch of wrapped, resizable buffers for serialized data (see Object Pooling). Whole HCHttp is based on it, so PatternLayout will not work here, because it serializes to String, not to ItemSource.
If your logs are already in JSON format, you can use messageOnly flag to send the log as-is with following configuration:
Otherwise, you can override LogEvent and Message serializers with JacksonMixIn (see docs) to get desired effect.
With HCHttp, PooledItemSourceFactory config is crucial here. It tells JacksonJsonLayout to use specified factory to serialize logs. Factory in the layout defines buffers for logs (1024 bytes in this case, adjust for your logs accordingly). Factory in HCHttp defines buffers for batch requests.
Good day, sir I am having a small issue here , could really use your advices or recommendations.
Currently I'm trying to append logs into elastic using Elasticsearch appender configuration with Jest client:
<Elasticsearch name="SERVICE_LOGS_ELASTICSEARCH"> <IndexName indexName="java-service-${bundle:application:info.build.archiveBaseName}"/> <PatternLayout pattern="%m%n"/> <AsyncBatchDelivery batchSize="1000" deliveryInterval="5000"> <JestHttp serverUris="${bundle:application:spring.elasticsearch.jest.uris}" mappingType="_doc"/> </AsyncBatchDelivery> </Elasticsearch>
You might be wondering , why would i use PatternLayout in the elastic appender , but the main reason for that is because I am using custom messages whenever I'm logging to escape log4j2 inserted metadata in the log message. Everything is working just fine with such configuration for elastic appender. A little bit later I decided to use HCHttp client instead of Jest client because it was mentioned in documentation , that it is more optimized. Here is configuration of appender:
<Elasticsearch name="SERVICE_LOGS_ELASTICSEARCH"> <IndexName indexName="java-service-${bundle:application:info.build.archiveBaseName}"/> <PatternLayout pattern="%m%n"/> <AsyncBatchDelivery batchSize="1000" deliveryInterval="5000"> <HCHttp serverUris="${bundle:application:spring.elasticsearch.jest.uris}"> <PooledItemSourceFactory poolName="batchPool" itemSizeInBytes="1024000" initialPoolSize="3"/> </HCHttp> </AsyncBatchDelivery> </Elasticsearch>
So , this configuration would not wrok , throwing java.lang.UnsupportedOperationException: Use ItemSource based API instead.
Here is the my app link , if you wonder about what I am trying to achieve : https://github.com/jafarjafarov/actuatorSwaggerCRUDSample. The main idea is to allow the exposure of different java objects in elastic in json format during some flow execution.
Thanks in advance
The text was updated successfully, but these errors were encountered: