gpt4 book ai didi

Android:如何集成Log4j2?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:43 24 4
gpt4 key购买 nike

我尝试在 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");

最佳答案

您需要在类路径中同时拥有核心和 api jar。 (请参阅 log4j2 常见问题页面。)

关于Android:如何集成Log4j2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20348351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com