Android:如何集成Log4j2?

时间:2013-12-03 10:19:10

标签: android log4j2 rsyslog

我正在尝试在Android中集成 Log4j2 ,但收到以下错误消息:

  

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");

1 个答案:

答案 0 :(得分:0)

你需要在类路径中同时拥有core和api jar。 (参见log4j2 FAQ页面。)