Comments (11)
<Elasticsearch name="ELASTICSEARCHASYNCBATCH" >
<IndexName indexName="log4j2" />
<AsyncBatchDelivery>
<ElasticsearchBulkProcessor serverUris="http://myurl">
<XPackAuth>
<BasicCredentials username="elasticsearch" password="elasticsearch123" />
</XPackAuth>
</ElasticsearchBulkProcessor>
</AsyncBatchDelivery>
</Elasticsearch>
from log4j2-elasticsearch.
You're right, but I didn't write XPackAuth
for this scenario.
Could you test it with your own build and modified org.appenders.log4j2.elasticsearch.bulkprocessor.XPackAuth
(remove @required and null check)? If not, I'll test it out with more relaxed rules and nginx in between and publish a SNAPSHOT for you before I include it in 1.3.1.
from log4j2-elasticsearch.
I did your test with a local build and got
2019-01-16 10:10:44,825 main ERROR Could not create plugin of type class org.appenders.log4j2.elasticsearch.AsyncBatchDelivery for element AsyncBatchDelivery: java.lang.NullPointerException java.lang.NullPointerException
at org.appenders.log4j2.elasticsearch.bulkprocessor.XPackAuth.configure(XPackAuth.java:51)
@Override
public void configure(Settings.Builder settings) {
credentials.applyTo(settings);
==> certInfo.applyTo(settings);
}
from log4j2-elasticsearch.
Null check should do the trick here, but have in mind that BulkProcessorObjectFactory.getClientProvider() returns PreBuiltXPackTransportClient - it may have more limitations. If you have issues with log4j2-elasticsearch6-bulkprocessor
, log4j2-elasticsearch-jest
will give you what you need.
I've started to work on more relaxed rules in all modules yesterday. It should be finished within the next few days.
from log4j2-elasticsearch.
Ok, I have to mention a couple of things here:
- I've relaxed the requirement for
certInfo
inlog4j2-elasticsearch-jest
; you should be able to useJestHttp
with clusters secured only with credentials (wil be released in 1.3.1 probably this week) - I've noticed that the error message you provided contains org.appenders.log4j2.elasticsearch.jest.XPackAuth from
-jest
module, but log4j2.xml config usesElasticsearchBulkProcessor
from-bulkprocessor
module; this will not work - you should use only one of the client modules:-jest
(for all versions) or one of-bulkprocessor
(specific to your cluster version) -bulkprocessor
module uses TCP client with custom protocol - it cannot be secured in a way that you expect; curl works because you execute it against HTTP, not TCP port; if you're not using XPack, you have to switch to-jest
module (HTTP client) to get it working.
Please have a look at the commit mentioned above and see if it meets your expectations.
from log4j2-elasticsearch.
pulled your changes and build locally:
log4j config
<Elasticsearch name="elasticsearchAsyncBatch">
<IndexName indexName="log4j2" />
<AsyncBatchDelivery batchSize="1000" deliveryInterval="5000" >
<JestHttp serverUris="????" >
<XPackAuth>
<BasicCredentials username="????" password="????" />
</XPackAuth>
</JestHttp>
</AsyncBatchDelivery>
</Elasticsearch>
maven …
<dependency>
<groupId>org.appenders.log4j</groupId>
<artifactId>log4j2-elasticsearch-jest</artifactId>
<version>1.3.1-SNAPSHOT</version>
</dependency>
running springboot …
at startup
2019-01-22 16:57:45,280 main INFO BatchEmitterFactory class found org.appenders.log4j2.elasticsearch.jest.BulkEmitterFactory
2019-01-22 16:57:45,285 main INFO Using org.appenders.log4j2.elasticsearch.jest.BulkEmitterFactory@1d76aeea as BatchEmitterFactoryProvider
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:146)
at io.searchbox.client.config.HttpClientConfig$Builder.build(HttpClientConfig.java:297)
at org.appenders.log4j2.elasticsearch.jest.JestHttpObjectFactory$JestClientProvider.createClient(JestHttpObjectFactory.java:271)
at org.appenders.log4j2.elasticsearch.jest.JestHttpObjectFactory$JestClientProvider.createClient(JestHttpObjectFactory.java:260)
at org.appenders.log4j2.elasticsearch.jest.JestHttpObjectFactory.createClient(JestHttpObjectFactory.java:102)
at org.appenders.log4j2.elasticsearch.jest.JestHttpObjectFactory$1.(JestHttpObjectFactory.java:112)
at org.appenders.log4j2.elasticsearch.jest.JestHttpObjectFactory.createBatchListener(JestHttpObjectFactory.java:109)
at org.appenders.log4j2.elasticsearch.jest.BulkEmitterFactory.createInstance(BulkEmitterFactory.java:40)
at org.appenders.log4j2.elasticsearch.jest.BulkEmitterFactory.createInstance(BulkEmitterFactory.java:30)
at org.appenders.log4j2.elasticsearch.spi.BatchEmitterServiceProvider.createInstance(BatchEmitterServiceProvider.java:70)
at org.appenders.log4j2.elasticsearch.AsyncBatchDelivery.(AsyncBatchDelivery.java:50)
at org.appenders.log4j2.elasticsearch.AsyncBatchDelivery$Builder.build(AsyncBatchDelivery.java:122)
at org.appenders.log4j2.elasticsearch.AsyncBatchDelivery$Builder.build(AsyncBatchDelivery.java:84)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
at org.apache.logging.log4j.core.config.AbstractConfiguration. at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.commons.logging.LogAdapter$Log4jLog.(LogAdapter.java:135)
at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:102)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:79)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
at org.springframework.boot.SpringApplication.(SpringApplication.java:194)
at pxm.rosy.ocs.jconfig.Application.main(Application.java:16)
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.LogAdapter$Log4jLog.(LogAdapter.java:140)
at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:102)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:79)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
at org.apache.http.conn.ssl.AbstractVerifier.(AbstractVerifier.java:61)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:44)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:46)
... 35 more
from log4j2-elasticsearch.
Error comes from io.searchbox:jest:HttpClientConfig:297 (so the XPackAuth
patch worked correctly)
if (this.httpsIOSessionStrategy == null) {
this.httpsIOSessionStrategy = SSLIOSessionStrategy.getSystemDefaultStrategy();
}
org.apache.http.conn.ssl.AbstractVerifier tries to obtain the Logger before Log4j2 config is ready and it leads to a chicken-egg problem.
Could you send me a zip with minimal project that reproduces it?
from log4j2-elasticsearch.
It's a bug in AsyncBatchDelivery
. IndexTemplate
is sent to cluster during initialization (basically, early Log4j2 configuration phase) when LoggerContext
is not ready yet. It causes premature HTTP client initialization when loggers requested by underlying classes are not available.
I'll introduce basic life cycle to patch it in 1.3.1 and extend the life cycle in 1.4 (maybe earlier).
WORKAROUND Add
private static final Logger LOG = LogManager.getRootLogger()
(or any other Logger)
to your Application class to initialize LoggerContext before Spring Boot starts . It's very nasty, because the whole plugin will be initialized more than once, but at least it will let you start the application.
from log4j2-elasticsearch.
workaround is OK, thanks for your effort
from log4j2-elasticsearch.
Glad to help. Thanks for the feedback! 👍
I'll commit a fix over the weekend and release it next week. Could you retest it then and close the issue if everything goes well, please?
from log4j2-elasticsearch.
I did a retest with 1.3.0 and it is ok
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.