Remove onFlyCompress message from logcat

一世执手 提交于 2019-12-22 01:46:05

问题


I am using YuvImage to compress the android.hardware.Camera feed to jpeg. Since then, I keep seeing skia onFlyCompress messages in logcat, which completely pollutes it. Is there any way to disable this message? I know I can filter the logcat output but that means doing it everywhere all the time, which is not a fix but a workaround. I simply don't want those messages printed at all


回答1:


You may can (i am not sure) subclass the class YuvImage which prints log and override the method of that class which prints the log and simply copy all code of that method but the Log.d() or Log.v() or Log.w() , ... code to the overridden method.

Look at the following answer too:

How do I enable/disable log levels in Android?




回答2:


Short answer

Try accomplishing your goal with method hooking.

You can hook android.util.log methods using XPosed Framework on ROOTed devices.

Detailed methods

  1. Use XPosed Framework to hook the android.util.Log's methods.
  2. In the hooking method, check if the message contains skia onFlyCompress.
  3. If then call setResult(null); to prevent it from printing out the log message.

Though these methods can only be used on rooted devices, but I hope my answer help at least some users that can use rooted devices.

(Hmm, because no customers will have to block the log messages, so all you need to do is to just root your local device only and install the auto-filtering app that uses XPosed framework.)

To see an example of blocking a method from executing rest of its code: This answer(especially the last paragraph) contains some examples to use Xposed framework. As you can see, the codes are very short(no longer than 40 lines.)

I will implement some codes if needed/seen potentially useful.

Sample code snippet

As someone upvoted mine, I assume that someone liked my suggestions. So I post some codes.

import android.util.*;
import de.robv.android.xposed.*;
import de.robv.android.xposed.callbacks.XC_LoadPackage.*;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

public class LogFilterApp implements IXposedHookLoadPackage
{

    private String TAG="LogFilter";
     public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable
{
    XposedBridge.log("Package name: " + lpparam.packageName);

            try
            {
                    findAndHookMethod("android.util.Log", lpparam.classLoader, "i", String.class, String.class, new XC_MethodHook()
                    {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable
                        {
                            //do something before
                            if(((String)(param.args[1])).indexOf("skia onFlyCompress")>=0)
                                                          { 
                                                          param.setResult(null);
                                                           }
                        }
                    });
            }
            catch (XposedHelpers.ClassNotFoundError e)
            {
                XposedBridge.log("ClassNotFoundError");
            }
            catch (NoSuchMethodError e)
            {
                XposedBridge.log("NoSuchMethodError");
            }
        }
     }
   }
}

Code reference: this XDA thread

Install XPosed Framework

XPosed Dev tutorial



来源:https://stackoverflow.com/questions/43244091/remove-onflycompress-message-from-logcat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!