[
https://issues.apache.org/jira/browse/LOG4J2-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16095974#comment-16095974
]
Ajitha edited comment on LOG4J2-1921 at 7/21/17 8:50 AM:
---------------------------------------------------------
Friends,
I want to give a background on the requirement, so that you can understand my
problem better.
We were mainly using log4j for following purposes:
>I dont want logs to be written to the default Android's adb which is what
>"android.util.Log.d" is doing. My end user will share that file via email for
>me to debug their issues/problems.
>We wanted to ALWAYS redirect the logs to a file rather than default logging
>console of Android.
>We have two layers - application layer and middleware layer. Log4j was
>thread-safe to post logs
>All other platforms like Windows were using log4j and we were aligned with
>other platforms of our application.
The code we follow is exactly like in
"https://github.com/loune/log4j2-android" . Our application was using v2.3 of
log4j-api and log4j-core. And it was fine and due to some issue we wanted to
upgrade and we faced the problem.
We were doing following:
1)On the app launch, we initialised log4j as in the example app using my "xml
configuration" file as shown in
https://github.com/loune/log4j2-android/blob/master/Log4jExampleApp/app/src/main/java/net/loune/log4jexampleapp/App.java
{code:java}
AndroidLog4jHelper.initialise(this.getApplicationContext(), R.raw.log4j_debug);
{code}
2) After that user can anytime change the logging levels through a menu option
and when the user changes the log level, we used below code to update log
levels.
{code:java}
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig =
config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(loglvl);
ctx.updateLoggers();
{code}
This was my total use-case.
In latest release of log4j-api-android , I am not able to see any methods which
can get my config file and give me a output file with logs written. As much as
I understand it writes logs to the android logging console which is not my
use-case.
I am not able to proceed. Is it just possible to remove the "java 9" classes
from log4j-core and give us a release addressing our use-case.
Sorry to trouble you guys. We have been benefitted by your library greatly
which was very much robust. Please help us here.
-Ajitha Yasmin S
was (Author: ajitha):
Friends,
I want to give a background on the requirement, so that you can understand my
problem better.
We were mainly using log4j for following purposes:
>I dont want logs to be written to the default Android's adb which is what
>"android.util.Log.d" is doing. My end user will share that file via email for
>me to debug their issues/problems.
>We wanted to ALWAYS redirect the logs to a file rather than default logging
>console of Android.
>We have two layers - application layer and middleware layer. Log4j was
>thread-safe to post logs
>All other platforms like Windows were using log4j and we were aligned with
>other platforms of our application.
The code we follow is exactly like in
"https://github.com/loune/log4j2-android" . Our application was using v2.3 of
log4j-api and log4j-core. And it was fine and due to some issue we wanted to
upgrade and we faced the problem.
We were doing following:
1)On the app launch, we initialised log4j as in the example app using my "xml
configuration" file as shown in
https://github.com/loune/log4j2-android/blob/master/Log4jExampleApp/app/src/main/java/net/loune/log4jexampleapp/App.java
{code:java}
AndroidLog4jHelper.initialise(this.getApplicationContext(), R.raw.log4j_debug);
{code}
2) After that user can anytime change the logging levels through a menu option
and when the user changes the log level, we used below code to update log
levels.
{code:java}
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig =
config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(loglvl);
ctx.updateLoggers();
{code}
This was my total use-case.
In latest release og log4j-api-android , I am not able to see any methods which
can get my config file and give me a output file with logs written. I am not
able to proceed. Is it just possible to remove the "java 9" classes from
log4j-core and give us a release addressing our use-case.
Sorry to trouble you guys. We have been benefitted by your library greatly
which was very much robust. Please help us here.
-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)