[ 
https://issues.apache.org/jira/browse/LOG4J2-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16028535#comment-16028535
 ] 

Ajitha commented on LOG4J2-1921:
--------------------------------

@Ralph et all : 

1) Android does not support java 9 yet. So I m not able to use the jar file. It 
wil take another few months  for the support to be added. 

2) since the api jar file is not compatible, I was not able to use it. So I 
thought of using 2.8.2 version of jar for log4j api and 2.8.3 version of jar 
for log4j core. This is where I got the class cast exception. I guess log4j 
does not allow incompatible core and api jars.

I m working from India. So tomorrow during my day, I shall try taking the 
source code of 2.8.3 api and 2.8.3 core and try compiling it from Android 
studio directly.  

I will get back to you in this thread in case of issues. 

Usually we - Android developers used to take the links from maven repo and put 
it in gradle . Now we will take the source from apache repo and try building it 
with the Java compiler that comes with Android SDK.

 If there is any modifications that I need to do for avoiding java 9 classes 
let me know. 

> 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
>
> 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.3.15#6346)

Reply via email to