i have followed the hazelcast docs for supporting log4j using below link:
https://docs.hazelcast.org/docs/latest/manual/html-single/#logging-configuration
but even after doing so i am not able to get hazelcast logs.
queries:
do we explicitly need to add log4j-1.2.17.jar file and add this dependency to pom.xml file? if yes
please let me know what is missing in hazelcast docs
is it possible to troubleshoot and check what is the error ?
There is a note in the Hazelcast reference manual section you've shared. It explains the thing:
If you choose to use log4j, log4j2, or slf4j, you should include the proper dependencies in the classpath.
It means, yes. If you use a logging framework different from the java.util.logging, then you have to provide the implementation yourself.
If you don't provide the proper implementation, the node fails to start:
java -Dhazelcast.logging.type=log4j -jar \
~/.m2/repository/com/hazelcast/hazelcast/3.12.5/hazelcast-3.12.5.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.hazelcast.logging.Log4jFactory.createLogger(Log4jFactory.java:29)
at com.hazelcast.logging.LoggerFactorySupport$1.createNew(LoggerFactorySupport.java:32)
at com.hazelcast.logging.LoggerFactorySupport$1.createNew(LoggerFactorySupport.java:30)
at com.hazelcast.util.ConcurrencyUtil.getOrPutIfAbsent(ConcurrencyUtil.java:125)
at com.hazelcast.logging.LoggerFactorySupport.getLogger(LoggerFactorySupport.java:38)
at com.hazelcast.logging.Logger.getLogger(Logger.java:110)
at com.hazelcast.logging.Logger.getLogger(Logger.java:64)
at com.hazelcast.instance.HazelcastInstanceFactory.<clinit>(HazelcastInstanceFactory.java:67)
at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:91)
at com.hazelcast.core.server.StartServer.main(StartServer.java:46)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more
log4j is deprecated since 5 years ago, has security vulnerabilities and may not work on newer versions of Java. See here.
Specifying hazelcast.logging.type as log4j indicates to Hazelcast to use whatever Log4j it finds at runtime, as this enables you to chose the version you want.
So your pom needs to build an executable Jar including at least the Hazelcast jar and Log4j jar. Or, you put both on the classpath for runtime.
For me, 3.12.5 fails immediately with
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
if I request Log4j but don't provide a Log4j jar on the runtime classpath. If you
don't get that message it could be that the configuration you specified isn't being used.
Related
We need to migrate to log4j 2.17 if we are using log4j jar, mvn dependency: tree showing only log4j-over-slf4j:jar. so I assume app is safe as it will redirect call to sl4j not to log4j.
Please confirm my app is safe with this jar without any remediation.?
In the SLF4J website, in the Comments on the log4shell(CVE-2021-44228) vulnerability they state that:
If you are using log4j-over-slf4j.jar in conjunction with the SLF4J API, you are safe unless the underlying implementation is log4j 2.x.
So it basically depends on how you're implementing the logs' generation. Slf4j natively uses logback. But to be sure, you can check your pom.xml and see if log4j is mentioned there.
I made a plug-in project from this article.
Then I add this plug-in into my project. However, when I try to use it,
I got the following error:
java.lang.NoClassDefFoundError: org/apache/sel4j/log4j/api/LoggerFactory
Caused by: java.lang.ClassNotFoundException: org.apache.sel4j.log4j.api.LoggerFactory
What should I do?
Do you have the same setup as on this screenshot?:
Note, that you need to add your jars to the classpath as shown on the screenshot and not as you would usually do it for your Java application: Right Click-> Add to build path.
Also, I would like to suggest using this article for setting up logging with Eclipse-RCP for the first time. It is more complete and precise.
My project is using log4j2, and everything looks fine until running an application that uses a third party library that uses log4j 1.x. When our application starts, we get an annoying stack trace involving a ClassNotFoundException on org.apache.log4j.ConsoleAppender. I noticed that one of our dependencies has a log4j.properties inside its jar referencing org.apache.log4j.ConsoleAppender, so I'm guessing that's the reason for the stack trace. A couple other dependencies causing this error include most anything using JBoss logging classes, like embedded glassfish and the eclipse persistence packages.
I tried adding log4j-1.2.bridge api jar to the classpath and it had no effect.
It seems a little ridiculous to include both the jars for log4j2 and log4j1.x in our application classpath. Is there any other alternative or fix?
These links provided answers for me:
https://issues.apache.org/jira/browse/LOG4J2-172
https://issues.jboss.org/browse/JBLOGGING-95
It looks like we are using an out-dated version of JBoss logging that doesn't support log4j2. However, I'm still not sure what to do for the one dependency that includes a log4j.properties.
[edit] It turns out adding log4j-jcl-2.0 jar worked for that dependency.
I get below error and the log files is not created. I know log4j.properties is not being picked correctly
log4j:WARN No appenders could be found for logger
log4j jar is in lib and classpath
log4j.properties is in src folder and gets loaded to classes folder on build
I tried many ways to fix this error like adding services folder with log4j implementation class to fix WAS logging conflict also tried sfl4j
Has anyone found a way to fix log4j issue with WAS7 or later ?
You can troubleshoot Log4J itself by specifying the log4j.debug=true system variable. Then you'll know exactly what's going on with Log4J, internally.
Does your log4j.properties file contain any logger definitions? perhaps you can paste the file here?
I had this same problem (WAS ignoring my META-INF/services/org.apache.commons.logging.LogFactory file).
The problem was solved when I downgraded commons-logging to 1.0.3, to match WAS version. Check this article for more info.
Consider using the Java Logging framework instead, which is built into the standard Java Runtime Environment and requires no additional installations or configuration. The relevant classes are in the java.util.logging package and there is an overview of the process for using them here (it works in a very similar way to log4j).
I'm developing a web application using JSF 2.0, NetBeans 6.9.1, GlassFish Server 3.1, mojarra 2.0.3, and JasperReports 3.7.6. Included in my project library is the jar file "xerces-2.8.0.jar". This file was imported as part of the JasperReports jar file library. Whenever I try to deploy, run, or debug my project through NetBeans, I receive this error:
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory.
After any change in my project my build fails, and I receive the above error, when I try to deploy, run, or debug it. I have to restart the server and run/debug a second time. I've searched the internet and cannot find a solution to this problem. I've looked at the jar file in question, and and DTDDVFactoryImpl does indeed extend from DTDDVFactory - I don't know why I'm receiving this error. While I can eventually get my project running, it would be much nicer if I wasn't receiving this error.
Can anyone please tell me how I can fix this? Do I need to remove this file from my project library? Do I need to update this file with a newer version/older version?
If you provide your own xerces.jar, you have to do that through the Endorsed Standards Override Mechanism (java -Djava.endorsed.dirs=/path/to/xerces.jar), you are not allowed to just add it on the classpath (and will sooner or later run into trouble if you do). Let me explain.
JAXP is the Java API for XML Processing. The creation of JAXP objects (like parsers, XSLT transfomers, DOM Documents) is done through the factory/factory-method pattern so you can plugin a new JAXP implementation (it has to be newer than the one provided in your JRE). Xerces provides (part of) a JAXP implementation and contains endorsed standards (an endorsed standard is a Java API defined through a standards process other than the Java Community Process, see the Endorsed Standards Override Mechanism). You'll run in all kinds of troubles if you don't use the ESOM.
I got this error when using Selenium with Glassfish. I got around it by copying XML jars (xerces-*, xalan-*, xml-apis*, serialize*) from selenium/libs/ to $AS_HOME/lib/endorsed (for Glassfish 2) or to $AS_HOME/glassfish/lib/endorsed for Glassfish 4.