Giter Site home page Giter Site logo

Comments (22)

rfoltyns avatar rfoltyns commented on September 22, 2024

This is probably java.security being too restrictive or a simple class loading issue.

Which Log4j2 version are you using?
Which Tomcat version are you using?
Where are your Log4j2 jars? log4j2-core, log4j2-api, etc. Are they in <TOMCAT_HOME>/lib by any chance? If so, try
to put log4j2-elasticsearch-* and appenders-logging jars in there as well and see if it helps.

This problem will be solved in 2.0 (in a few months at least, probably next year) after shading Log4j2 classes into core jar. At the moment, I can't do anything more than recommend to ensure that these jars are loaded by the same classloader.

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Could you test it with latest change, please? I just pushed the snapshots to http://oss.sonatype.org/content/repositories/snapshots.

Add the repo to your pom.xml (or other build system equivalent) to get it:

<repositories>
    <repository>
        <id>oss.sonatype.org-snapshot</id>
        <url>http://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

You can also download the relevant jar here

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Yes. Version has to be changed from 1.5.0 to 1.5.1-SNAPSHOT and repositories section added to your pom file (Maven will have no clue how to locate these particular snapshots otherwise).

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

Right testing the new snapshot moved things forward, I can now see a log file in kibana! However.....still getting an error in the logs on startup.

[talledLocalContainer] 2021-03-05 08:25:55,466 main ERROR Unable to invoke factory method in class org.appenders.log4j2.elasticsearch.IndexTemplatePlugin for element IndexTemplate: java.lang.IllegalArgumentException: Requested classpath resource was null: classpath:indexTemplate.json java.lang.reflect.InvocationTargetException
[INFO] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:137)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
[INFO] [talledLocalContainer] at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
[INFO] [talledLocalContainer] at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
[INFO] [talledLocalContainer] at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
[INFO] [talledLocalContainer] at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
[INFO] [talledLocalContainer] at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
[INFO] [talledLocalContainer] at org.hippoecm.hst.site.container.HstContextLoaderListener.(HstContextLoaderListener.java:53)
[INFO] [talledLocalContainer] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[INFO] [talledLocalContainer] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[INFO] [talledLocalContainer] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[INFO] [talledLocalContainer] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[INFO] [talledLocalContainer] at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4607)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:631)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1831)
[INFO] [talledLocalContainer] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[INFO] [talledLocalContainer] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[INFO] [talledLocalContainer] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
[INFO] [talledLocalContainer] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:526)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:425)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
[INFO] [talledLocalContainer] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[INFO] [talledLocalContainer] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
[INFO] [talledLocalContainer] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
[INFO] [talledLocalContainer] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
[INFO] [talledLocalContainer] at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
[INFO] [talledLocalContainer] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
[INFO] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] [talledLocalContainer] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
[INFO] [talledLocalContainer] at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
[INFO] [talledLocalContainer] Caused by: java.lang.IllegalArgumentException: Requested classpath resource was null: classpath:indexTemplate.json
[INFO] [talledLocalContainer] at org.appenders.log4j2.elasticsearch.ResourceUtil.loadClasspathResource(ResourceUtil.java:80)
[INFO] [talledLocalContainer] at org.appenders.log4j2.elasticsearch.ResourceUtil.loadResource(ResourceUtil.java:56)
[INFO] [talledLocalContainer] at org.appenders.log4j2.elasticsearch.IndexTemplate$Builder.loadSource(IndexTemplate.java:119)
[INFO] [talledLocalContainer] at org.appenders.log4j2.elasticsearch.IndexTemplatePlugin.createIndexTemplate(IndexTemplatePlugin.java:65)
[INFO] [talledLocalContainer] ... 73 more
[INFO] [talledLocalContainer] Caused by: java.lang.IllegalArgumentException: Requested classpath resource was null: classpath:indexTemplate.json
[INFO] [talledLocalContainer] at org.appenders.log4j2.elasticsearch.ResourceUtil.loadClasspathResource(ResourceUtil.java:68)
[INFO] [talledLocalContainer] ... 76 more
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] 2021-03-05 08:25:55,491 main ERROR Null object returned for IndexTemplate in AsyncBatchDelivery.

With regards to versions
Tomcat 9x - not in control of that as its in the base bloomreach CMS build
Log4j2 - Not sure and cannot seem to find that version?

I am not adding any faster xml jackson references at the moment....

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

I have a feeling if its like npm or nuget there is no version set for log4j2... just this

org.apache.logging.log4j
log4j-core
provided

so its using the latest?

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

You need to provide an indexTemplate.json file in one of your jars in order to tell Elasticsearch how to map Log4j2 LogEvent fields.

You can find examples for all Elasticsearch versions here. indexTemplate-6.json is compatible with ES 5.x and 6.x. Once you package the template file in your jar, delete the index that was created a few minutes ago and restart the CMS app (index templates are applied on index creation)

Log4j2 version is most probably defined in the dependencyManagement section of parent pom. But, since it's making progress, it's probably not relevant anymore.

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

You can also use an absolute file path instead.

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

Hi, yeah trying to figure this out now...

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

I ended up adding the json to the log4j2 file for now.

Appreciate your help on this

Thanks
J

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Yeah, that'll work as well.

Given that the class access fix worked, I'll release it in 1.5.1 soon (most probably next week).

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

Awesome.
thanks
J

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Date column is timeMillis by default. It's of type long to reduce garbage. If you'd like to use @timestamp instead, you can configure it with JacksonMixIn as described here, but with slightly different mixin class

package foo.bar;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.logging.log4j.core.LogEvent;

@JsonSerialize(as = LogEvent.class)
public abstract class CustomLogEventMixIn extends ExtendedLogEventJacksonJsonMixIn {

    @JsonProperty("@timestamp")
    @Override
    public abstract long getTimeMillis();

}

If you'd like to have a different format, you can use JacksonMixIn as described here (with a few fixes, follow the issue until the end). I don't recommend this though - log4j2-elasticsearch-jest module generates enough garbage already, log4j2-elasticsearch-hc reduces it by >90%, but that's a topic for a different discussion.

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Long story short - mixins determine the shape and content of serialized Log4j2 LogEvent and index template determines how ES will interpret it. Once the first document is in, ES creates an index, applies index template on this index (the one defined by IndexTemplate tag) and then you can create an index pattern in Kibana with date column (timeMillis by default, @timestamp if you want to). Since date column is of type long, index template is there to tell ES that that is the case.

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

Hi, I got it all working locally. Still got two problems. Not related to this but in general.
How do I specify a username and password for elastic search as our instance is secure in the cloud?

Also in apache I am seeing this error
java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.selector.BasicContextSelector to org.apache.logging.log4j.core.selector.ContextSelector

Thoughts?

Appreciate your help.

Any news on the patch going to a minor version rather than a snapshot?

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

How do I specify a username and password for elastic search as our instance is secure in the cloud?

You need to add XPackAuth config to your Log4j2 configuration. Have a look here

java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.selector.BasicContextSelector to org.apache.logging.log4j.core.selector.ContextSelector

No idea. I've never seen that before. Could you post a full stacktrace?

Any news on the patch going to a minor version rather than a snapshot?

Waiting for one more PR. If I don't get any feedback from the contributor, I'll push it myself and release this evening.

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

If you're using AWS Elasticsearch service you'll not be able to authenticate (AWS service does not send back the WWW-Authenticate header). If that's the case, you'll need to extend a few classes.

If you're running regular ES, should be all good.

from log4j2-elasticsearch.

johnhydemtm365 avatar johnhydemtm365 commented on September 22, 2024

Awesome, thought I would check as that is what I am using, but it was not working. Have added the dependancy to xpack as well now as well will check later.
We are using cloud.io

Apache error, I will figure out.

Waiting for one more PR. If I don't get any feedback from the contributor, I'll push it myself and release this evening.
Awesome.

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Fixed in 1.5.1

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

Closing as the issue was fixed.

from log4j2-elasticsearch.

rfoltyns avatar rfoltyns commented on September 22, 2024

@johnhydemtm365 Did you manage to setup TLS? Is there anything else I can help you with?

from log4j2-elasticsearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.