-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error using log4j2 api/core libraries with Android #3056
Comments
Hi @nick-j-white49, Thanks for the report. Do you have a stack trace that shows where that error occurred? As far as I know no one among the core Log4j developers is using Android. Could you help us out, by submitting a minimal We could integrate such a project into our integration tests (which currently cover JPMS, GraalVM, OSGi, but no Android). |
Full stack trace as follows:
This seems to occur whenever an instance of org.apache.logging.log4j.Logger is returned (in the sample I will upload shortly, defined in the Activity scope). This does not cause any application crash however, and on further inspection in v2.24.1 I can see that once the logging configuration is set appropriately for the logger in use, logging commands are working as expected (pre-2.24 this was not the case!) The issues I'm currently facing seem related to log4j2 config initialisation at this point. I only seem to be able to use the root logger: which by default has LogLevel.ERROR set. This can be overridden using e.g. If I try to use any other logger: again, Level.ERROR is the default, but I am then unable to change the logging level. This is presumably because no configuration is available, so no other loggers are defined. It seems I can't get the application to read in a configuration from src/main/assets (which should be available on the log4j classpath). log4j2.properties:
Attempts to manually load using:
result in error:
|
PR submitted: apache/logging-log4j-samples#196 |
Thank you for the stacktrace and the example. Right now the only problem seems the |
This fixes three issues encountered in the [`log4j-samples-android`](https://github.com/apache/logging-log4j-samples/tree/main/log4j-samples-android) test project: 1. Disables the `jvmrunargs` lookup on Android and fixes it on the other platforms. Previously, the lookup always returned `null`. 2. Switches the default context selector to `BasicContextSelector` on Android. `StackLocator` is broken on Android: it cannot use our JDK 8 code (missing `sun.reflect` classes), but also it cannot use our JDK 11+ code (missing multi-release JAR support). This causes `ClassLoaderContextSelector` to use two different logger contexts for the same classloader. 3. Fixes a `ParserConfigurationException` caused by the lack of XInclude capabilities in Android's XML parser. The fix to [LOG4J2-3531](https://issues.apache.org/jira/browse/LOG4J2-3531) didn't cover all the cases. Closes #3056. Part of #2832.
This fixes three issues encountered in the [`log4j-samples-android`](https://github.com/apache/logging-log4j-samples/tree/main/log4j-samples-android) test project: 1. Disables the `jvmrunargs` lookup on Android and fixes it on the other platforms. Previously, the lookup always returned `null`. 2. Switches the default context selector to `BasicContextSelector` on Android. `StackLocator` is broken on Android: it cannot use our JDK 8 code (missing `sun.reflect` classes), but also it cannot use our JDK 11+ code (missing multi-release JAR support). This causes `ClassLoaderContextSelector` to use two different logger contexts for the same classloader. 3. Fixes a `ParserConfigurationException` caused by the lack of XInclude capabilities in Android's XML parser. The fix to [LOG4J2-3531](https://issues.apache.org/jira/browse/LOG4J2-3531) didn't cover all the cases. Closes #3056. Part of #2832.
This fixes three issues encountered in the [`log4j-samples-android`](https://github.com/apache/logging-log4j-samples/tree/main/log4j-samples-android) test project: 1. Disables the `jvmrunargs` lookup on Android and fixes it on the other platforms. Previously, the lookup always returned `null`. 2. Switches the default context selector to `BasicContextSelector` on Android. `StackLocator` is broken on Android: it cannot use our JDK 8 code (missing `sun.reflect` classes), but also it cannot use our JDK 11+ code (missing multi-release JAR support). This causes `ClassLoaderContextSelector` to use two different logger contexts for the same classloader. 3. Fixes a `ParserConfigurationException` caused by the lack of XInclude capabilities in Android's XML parser. The fix to [LOG4J2-3531](https://issues.apache.org/jira/browse/LOG4J2-3531) didn't cover all the cases. Closes #3056. Part of #2832.
Description
Using log4j2 v2.24.0 (api and core) with Android throws error:
gradle settings:
Configuration
Version: 2.24.0
Operating system: Android SDK34
JDK: 1.8
Logs
The text was updated successfully, but these errors were encountered: