Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1921

Getting ClassCastException while getting LoggerContext

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.8.2
    • 3.0.0-beta2
    • Configurators
    • Android

    Description

      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.

      LoggerContext ctx = LoggerContext.getContext()
              Configuration config = ctx.getConfiguration();
              LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
              loggerConfig.setLevel(myLogLevel);
              ctx.updateLoggers();
      

      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.

      Attachments

        1. Log4jExample_using_v2.3.zip
          22.19 MB
          Ajitha

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Ajitha Ajitha
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: