xlconnect icon indicating copy to clipboard operation
xlconnect copied to clipboard

StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

Open martinstuder opened this issue 3 years ago • 1 comments

With the current version on master (1.0.6.9999) I get the following error logged to the R console: ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

martinstuder avatar Aug 18 '22 17:08 martinstuder

See updated workaround

This is surprising to me, as POI explicitly indicates that they do not rely on log4j-core in their announcement regarding log4shell (visible on their homepage). The Change history also only mentions log4j-api. My conclusion from this is that they assume the application has to provide the logging implementation; I don't think we should provide one beyond SimpleLogger for the typical use case (especially given the kind of CVEs that can result as implied above).

spoltier avatar Sep 13 '22 15:09 spoltier

I have this issue too. any update perhaps? its not breaking anything but the error message in the logs is pretty annoying

cfisher5 avatar Dec 23 '22 17:12 cfisher5

Has anyone been able to figure this one out?

aleenatorres avatar Feb 01 '23 22:02 aleenatorres

If you would like ~~to provide a logging implementation in order~~ not to see this message, do the following:

  • find the installation location(s) of packages using .libPaths()
  • in one of the locations, you will find an XLConnect directory
  • copy the contents of log4j2.system.properties into a file of the same name into the /XLConnect/java directory.
  • Restart your R session and reload XLConnect.

Note that this is not necessary to use XLConnect.

spoltier avatar Feb 03 '23 11:02 spoltier

If you would like to provide a logging implementation in order not to see this message, do the following:

* find the installation location(s) of packages using `.libPaths()`

* in one of the locations, you will find an _XLConnect_ directory

* download [log4j core 2.19](https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.19.0/log4j-core-2.19.0.jar) - this may be out of date! see https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core for all versions.

* Put the downloaded jar in the _/XLConnect/java_ directory.

* Restart your R session and reload XLConnect.

Note that this is not necessary to use XLConnect.

We tried this and it broke our script. Instead of the error going away our script failed with this error:

ng.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
	at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
	at org.apache.poi.openxml4j.util.ZipSecureFile.(ZipSecureFile.java:37)
	at com.miraisolutions.xlconnect.Workbook.(Workbook.java:66)
	at com.miraisolutions.xlconnect.integration.r.RWorkbookWrapper.(RWorkbookWrapper.java:52)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at RJavaTools.newInstance(RJavaTools.java:358)
Caused by: java.lang.ClassNotFoundException
	at RJavaClassLoader.findClass(RJavaClassLoader.java:397)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 33 more
Error: NoClassDefFoundError (Java): Could not initialize class org.apache.logging.log4j.core.impl.ThreadContextDataInjector
Execution halted

ablackshear avatar Feb 05 '23 15:02 ablackshear

Does the Maven dependency xml from the page you linked need to be added here to make this work?

https://github.com/miraisolutions/xlconnect-java/blob/master/pom.xml

ablackshear avatar Feb 05 '23 16:02 ablackshear

@ablackshear there are no facilities in R to resolve JARs based on pom.xml. The issue is likely that POI 5.2.3 depends on log4j 2.18, so you will probably need to use 2.18. There are no mandatory runtime dependencies listed, so you shouldn't see any more errors.

spoltier avatar Feb 07 '23 10:02 spoltier

@ablackshear there are no facilities in R to resolve JARs based on pom.xml. The issue is likely that POI 5.2.3 depends on log4j 2.18, so you will probably need to use 2.18. There are no mandatory runtime dependencies listed, so you shouldn't see any more errors.

Thank you, that worked

ablackshear avatar Feb 08 '23 15:02 ablackshear

Will investigate if we can use a "noop logger", though this may not be included in the API jar.

spoltier avatar Feb 14 '23 10:02 spoltier

Setting the system property -Dlog4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory prevents the log from appearing. Example:

> options(java.parameters = "-Dlog4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory")
> XLConnect::writeWorksheetToFile("test.xlsx", mtcars, sheet = "mtcars")

Maybe we can include a log4j2.component.properties file in the classpath to set the logger context factory plus the default root logger level (OFF). See also https://logging.apache.org/log4j/2.x/manual/configuration.html

martinstuder avatar Mar 11 '23 09:03 martinstuder

Setting the system property -Dlog4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory prevents the log from appearing. Example:

> options(java.parameters = "-Dlog4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory")
> XLConnect::writeWorksheetToFile("test.xlsx", mtcars, sheet = "mtcars")

Maybe we can include a log4j2.component.properties file in the classpath to set the logger context factory plus the default root logger level (OFF). See also https://logging.apache.org/log4j/2.x/manual/configuration.html

This prevented the error (in the initial post) experienced in my Docker container.

asadow avatar Sep 15 '23 20:09 asadow

@asadow this has been fixed. If you see the error still, you should upgrade to the latest version of XLConnect (1.0.7)

spoltier avatar Sep 26 '23 09:09 spoltier