[
https://issues.apache.org/jira/browse/LOG4J2-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16094482#comment-16094482
]
Ajitha commented on LOG4J2-1921:
--------------------------------
Hi Team,
I did as mentioned above. I built logging-log4j2\log4j-api-android from the
given branch. It got built successfuly and generated jar. But log4j-core from
same branch was not compiling successfully. It was failing. So, I took latest
log4j-core jar from
"https://repository.apache.org/content/groups/snapshots/org/apache/logging/log4j/log4j-core/2.9-SNAPSHOT/"
. I put both the jar in my Android project and then tried to build.
_*Luckily the issue with java 9 classes were not coming this time*_. Thumbs up
guys!
But after running it on Android device, I got the "ClassCastException" that is
seen in this problem original statement.
My Android side implementation is exactly similar to the application here :
https://github.com/loune/log4j2-android
One change in above example is made:
https://github.com/loune/log4j2-android/blob/master/Log4jExampleApp/app/src/main/java/net/loune/log4j2android/AndroidContextSelector.java
Line no 34:
{code:java}
Configuration config =
org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getInstance().getConfiguration(source);
{code}
Replaced with:
{code:java}
Configuration config =
org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getInstance().getConfiguration(context,
source);
{code}
Please check if we are missing something while initialising the Log4j. Log4j
has helped us a lot of times :) Expecting your support. Thanks.
-Ajitha Yasmin S
> Getting ClassCastException while getting LoggerContext
> ------------------------------------------------------
>
> Key: LOG4J2-1921
> URL: https://issues.apache.org/jira/browse/LOG4J2-1921
> Project: Log4j 2
> Issue Type: Bug
> Components: Configurators
> Affects Versions: 2.8.2
> Environment: Android
> Reporter: Ajitha
> Priority: Blocker
> Labels: Android
>
> Hi,
> I integrated the log4j with my Android application and did the initial
> config. It works fine. I have a menu item in "Settings" screen where I can
> change the log levels in my application. So, After I change the
> configuration, I need to update the loggers. So I am using following logic.
> {code:java}
> LoggerContext ctx = LoggerContext.getContext()
> Configuration config = ctx.getConfiguration();
> LoggerConfig loggerConfig =
> config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
> loggerConfig.setLevel(myLogLevel);
> ctx.updateLoggers();
> {code}
> While getting the logger context, I am getting a ClassCastException.
> 05-26 22:33:21.011 E/AndroidRuntime( 9642): Caused by:
> java.lang.ClassCastException:
> org.apache.logging.log4j.simple.SimpleLoggerContext cannot be cast to
> org.apache.logging.log4j.core.LoggerContext
> 05-26 22:33:21.011 E/AndroidRuntime( 9642): at
> org.apache.logging.log4j.core.LoggerContext.getContext(LoggerContext.java:190)
> 05-26 22:33:21.011 E/AndroidRuntime( 9642): at
> org.apache.logging.log4j.core.config.Configurator.setRootLevel(Configurator.java:323)
> Please help here.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)