从系统类收集日志 [英] Collect logs from system classes

查看:173
本文介绍了从系统类收集日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Android的MediaMuxer录制屏幕的应用程序.使用Crashlytics,很多用户都遇到了无法阻止多路复用器崩溃"的问题,但是我无法在任何设备上本地复制它.根据另一个问题,MediaMuxer运行时生成的MPEG4Writer日志应指出问题的根源是什么,但是由于我无法在本地重现该问题,因此我需要远程收集这些日志并将其传递给Crashlytics.

I'm working on an app that uses Android's MediaMuxer for recording the screen. Using Crashlytics, a significant number of users have the "Failed to stop the muxer" crash, but I can't reproduce it locally on any of my devices. According to another question, the MPEG4Writer logs generated while MediaMuxer is running should indicate what the source of the problem is, but since I'm unable to reproduce it locally, I need to collect those logs remotely and pass them over to Crashlytics.

所以这是我的问题:MediaMuxer和MPEG4Writer是系统类,因此显然我无法对其进行编辑以添加Crashlytics.log()行.我曾考虑过让该应用读取Logcat输出并存储所有包含MPEG4Writer的条目,如果多路复用器崩溃,则将它们发送到Crashlytics,使用

So here's my problem: MediaMuxer and MPEG4Writer are system classes, so obviously I can't edit them to add Crashlytics.log() lines. I've thought of having the app read the Logcat output and storing all entries containing MPEG4Writer, which are then sent to Crashlytics if the muxer crashes, using this implementation as a base. Here's my code:

public class LogRetriever extends Thread {

    private static final String TAG = LogRetriever.class.getCanonicalName();
    public static ArrayList<String> logStorage = new ArrayList<>();
    private AtomicBoolean mLoggingActive = new AtomicBoolean(true);

    @Override
    public void run() {
        try {
            String[] command = new String[] { "logcat" };
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

            String line;
            while (mLoggingActive.get() && ((line = bufferedReader.readLine()) != null)){
                if(line.contains("MPEG4Writer")) {
                    logStorage.add(line);
                }
            }
        }
        catch (IOException ex) {
            Log.e(TAG, "start failed", ex);
        }
    }

    public void stopLogging() {
        mLoggingActive.set(false);
    }
}

使用上述方法,我似乎只得到了MPEG4Writer生成的前四行日志.其余部分可通过Android Studio的logcat看到,但未由我的代码收集.我也尝试过此库,它似乎在做同样的事情,但是同样,同样的问题,只是收集前4行.我怀疑MediaMuxer在这4行之后创建了自己的进程,此时我无法再读取其logcat输出,因为我的LogRetriever类现在处于不同的进程中.那么我应该如何收集这些日志?我在这里采用错误的方法吗?

Using the above method, I only seem to get the first four log lines generated by MPEG4Writer. The rest are visible through Android Studio's logcat, but aren't collected by my code. I've also tried this library which seems to do the same thing, but again, same problem, only the first 4 lines are collected. I suspect that MediaMuxer is creating its own process after those 4 lines, at which point I can no longer read its logcat output because my LogRetriever class is now in a different process. So how am I supposed to collect those logs? Am I taking the wrong approach here?

推荐答案

那我应该如何收集那些日志?

So how am I supposed to collect those logs?

通常,除非您为设备制造商服务,否则您不会收集这些日志.

Generally, unless you are working for a device manufacturer, you don't collect those logs.

首先,从未正式支持在运行时访问LogCat;因此,您必须采取笨拙的"fork logcat"方法.

First, accessing LogCat at runtime has never been officially supported; hence, the clunky "fork logcat" approach that you have to take.

除此之外,您还需要READ_LOGS权限才能获得比您要的更多的东西.该权限的protectionLevelsignature|privileged|development,这意味着普通应用无法持有该权限.

Beyond that, you need the READ_LOGS permission to get more than what you are. That permission has signature|privileged|development for the protectionLevel, meaning that ordinary apps cannot hold that permission.

这是出于隐私原因. READ_LOGS使您可以访问所有LogCat,许多应用程序(和某些系统进程)会记录可能敏感的信息.

This is for privacy reasons. READ_LOGS gives you access to all of LogCat, and lots of apps (and some system processes) log information that may be sensitive.

这篇关于从系统类收集日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆