添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
android log4j2,java - How to use log4j2 with Android for logcat output? - Stack Overflow 2021-05-28 22:57:14

I want to use log4j2 to produce logcat output from an Android app.

Seems that the 6 standard log4j2 log levels (fatal, error, warn, info, debug, trace) are matching well to the 6 log levels of logcat (wtf, e, w, i, d, v). The log4j logger name (typically the class name) should be used for the logcat tag.

This small Android project compiles using mvn clean install (after installing Android sdk et cetera).

In it's main activity (Mpjoe.java), it includes something like:

import org.apache.logging.log4j.LogManager;

import org.apache.logging.log4j.Logger;

// ...

public class Mpjoe extends Activity {

static final Logger logger = LogManager.getLogger();

// ...

@Override public void onCreate(Bundle savedInstanceState) {

// ...

logger.fatal("=== Initialized ===");

As mentioned here, I'd added the required dependencies to my pom.xml:

org.apache.logging.log4j

log4j-api

org.apache.logging.log4j

log4j-core

For configuring log4j2 without a configuration file, I use this helper class (which uses the same way as mentioned here).

It compiles without errors, but when running I got the message:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

When checking the system property java.class.path, it returns ".", but this seems a normal circumstance (as described on http://developer.android.com).

Any suggestions how to solve that?

将依赖项添加到应用程序级别的build.gradle中: dependencies { compile 'com.github.mobile-dev-pro:remote- logcat :VERSION' onCreate()方法中主应用程序类中的初始化库: public class App extends Application { @Override public void onCreate () { super 在项目 app 模块下的 build.gradle 文件中加入 dependencies { // 日志调试框架:https://github.com/getActivity/ Logcat debugImplementation 'com.github.getActivity: Logcat :9.6' 无需调用,直接运行,然后授予悬浮窗权限即可 在 debug 模式下运行即可,在 release 正式打包的时不会集成本库,尽 Log4j2 的配置、使用 最近公司让调研 log4j2 Android 中的使用,在网上查了很多资料,在这做个总结,一起学习,参考了许多文章,文末都有链接,感谢大佬们的文章 Log4j2 简介 log4j2 是log4j 1.x 的升级版,2015年5月,Apache宣布log4j1.x 停止更新。最新版:官网下载 log4j2 参考了logback的一些优秀的设计,并且修复了一些问题,因此带来了一些重大的提升,主要有: 异常处理:在logback中,Appender中的异常不会被应用感知到,但是在log4j [TOC]1. 版本选择推荐使用log4j-2.11推荐使用slf4j作为日志门面2. pom依赖配置和升级方案pom配置org.slf4jslf4j-api1.7.24org.apache.logging.log4jlog4j-1.2-api2.11.0org.apache.logging.log4jlog4j-core2.11.0org.apache.logging.log4jlog4j-ap... 备注:转载,原文地址:https://www.cnblogs.com/hafiz/p/6170702.html 1、关于配置文件的名称以及在项目中的存放位置   log4j 2.x版本不再支持像1.x中的.properties后缀的文件配置方式,2.x版本配置文件后缀名只能为".xml",".json"或者".jsn"。   系统选择配置文件的优先级(从先到后)如下: classpath下的名为... 使用 log4j2 需要两个包:apache官网上有的下:我使用的是log4j-api-2.5.jar和log4j-core-2.5.jar。读取配置文件方法:System.setProperty("log4j.configurationFile", “文件存放路径”);配置文件读取:// java 加载src下的配置文件//src下的配置文件会默认的被log4j的框架加载(文件名必须 log4j2 .xml... 本人近年都在做 Android 项目,最近有个纯 Java 项目紧张,临时介入其中。日志模块,控制端显示不同等级日志同时保存到文件中,要求每天保存一个日志文件,日志目录保留最近30天日志文件。最初没想到用库,自己采用线程池方式写日志,在写日志时先判断是否有30天前的日志删除,然后对比时间判定是否有当天日志文件,之后采用BufferedWriter写日志。写好后,客户进行代码审查,不太相信我写的效率,要求采 目前在进行 Android 开发时使用到了log4j,现在对其配置进行记录。 1. android -logging-log4j 下载地址 https://code.google.com/archive/p/ android -logging-log4j/ 2. 所依赖的apache的log4j库的下载地址 http://logging.apache.org/log4j/1.2/download ConfigurationInserting log requests into the application code requires a fairamount of planning and effort. Observation shows that approximately 4percent of code is dedicated to logging. Consequently,... 用asyncRoot配置對應的對接disruptor類是AsyncLoggerConfigDisruptor,用Log4jContextSelector啟動參數配置全局異步的對應的對接disruptor類是AsyncLoggerDisruptor。下面分析的是AsyncLoggerConfigDisruptordisruptor的創建與啟動需要的部件實現AsyncLoggerConfigDisru... 官方文档:http://logging.apache.org/log4j/2.x/manual/configuration.html Log4j2 简介 log4j2 是log4j 1.x 的升级版,2015年5月,Apache宣布log4j1.x 停止更新。最新版为1.2.17。 log4j2 借鉴了logback的一些优秀的设计,并且修复了一些问题,因此带来了一些重大的提升,主要有: 1、异常处理:在logback中,Appender中的异常不会被应用感知到,但是在 log4j2 中,提供了一些异常处理机制。 在 android 中,实现输出log内容到sd卡中的文件里面,做法是:1.导入者两个jar包2.测试代码importde.mindpipe. android .logging.log4j.LogConfigurator; import java .io.File; import android .os.Environment; importorg.apache.log4j.Leve... Download Apache Log4j 2Apache Log4j 2 is distributed under the Apache License, version 2.0.The link in the Mirrors column should display a list of available mirrors with a default selection based on y... 我正在尝试在 Android 中集成 Log4j2 ,但收到以下错误消息: java .lang.ClassCastException: org.apache.logging.log4j.simple.SimpleLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContextimport org.apache.loggin... logback-access logback-core是核心模块,logback-classic是日志框架,相当于log4j,logback很好的实现了slf4j,logback-access提供跟web 容器有关的日志访问功能。 logback与l...