Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to integrate Log4j2?

I'm trying to integrate Log4j2 in Android but getting the following error message:

java.lang.ClassCastException: org.apache.logging.log4j.simple.SimpleLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.SyslogAppender;

  LoggerContext context = (LoggerContext) LogManager.getContext();
  Logger root = context.getLogger("MainActivity");
  SyslogAppender appender = obtainAppender();

  if (!appender.isStarted()) 
    appender.start();

  root.addAppender(appender);
  root.setAdditive(false);
  root.setLevel(Level.DEBUG);
  root.debug("This is a test message");
like image 882
Gkapoor Avatar asked Nov 23 '22 09:11

Gkapoor


1 Answers

You need to have both the core and api jar in the classpath. (See the log4j2 FAQ page.)

like image 95
Remko Popma Avatar answered Dec 16 '22 04:12

Remko Popma