我应该创建我的最终方案时,评论我的日志电话?我的、电话、方案、日志

2023-09-12 11:07:25 作者:Ganme丶柠檬

我有一个使用了大量Log.d()或Log.e(的)要求进行调试的应用程序。现在,我要创建我的最终方案公布。从Eclipse的Andr​​oid的导出功能提到删除可调试标志,在清单中,这是我做的事。我应该也评论所有的记录呼叫来提高我的应用程序,或将无助于非调试的最终版本封装这些调用的表现?

I have an application that uses a lot of Log.d() or Log.e() calls for debugging. Now I want to create my final package for release. The Android Export feature from Eclipse mentions to remove the "Debuggable" flag in the manifest, which I have done. Should I also comment all the Log calls to improve the performance of my application or these calls will do nothing in the non debuggable final version package ?

推荐答案

我已经子类登录类,一类称为跟踪,这反映方法上登录。所以,我做Trace.d(TAG,嗒嗒),然后Trace.d方法中的code只执行基于所谓LOGGING_LEVEL静态final类变量,其中只有1-5级别(无,错误,错误和放大器;警告,错误和放大器;警告和放大器;信息和一切,包括调试)。在制作生产APK,Proguard的删除所有未在应用程序中使用的code,所以它确实对我来说。

I have subclassed the Log class to a class called Trace, which mirrors methods on Log. So I do Trace.d(TAG,"blah") and then within the Trace.d method the code only executes based on a static final class variable called LOGGING_LEVEL, which has levels 1-5 (none, errors only, errors & warnings, errors & warnings & info, and everything including debug) . When producing a production APK, Proguard removes all the code that isn't used in the application, so it does it for me.

对于我来说,日志是太重要,从源头上消除,但必须从生产应用程序被删除,性能,安全和知识产权的原因。

For me, logging is far too important to remove from the source, but it must be removed from the production application, for performance, secure and intellectual property reasons.

这个结构可以让我多了很多记录添加到应用程序,这使得调试问题要容易得多,但任何对生产APK没有任何影响

This structure allows me to add a lot MORE logging to the application, which makes debugging problems much easier, but with no impact whatsoever on the production APK

public class Trace
{
    public static final int    NONE                         = 0;
    public static final int    ERRORS_ONLY                  = 1;
    public static final int    ERRORS_WARNINGS              = 2;
    public static final int    ERRORS_WARNINGS_INFO         = 3;
    public static final int    ERRORS_WARNINGS_INFO_DEBUG   = 4;

    private static final int          LOGGING_LEVEL   = ERRORS_ONLY;        // Errors + warnings + info + debug (default)

    public static void e(String tag, String msg)
    {
        if ( LOGGING_LEVEL >=1) Log.e(tag,msg);
    }

    public static void e(String tag, String msg, Exception e)
    {
        if ( LOGGING_LEVEL >=1) Log.e(tag,msg,e);
    }

    public static void w(String tag, String msg)
    {
        if ( LOGGING_LEVEL >=2) Log.w(tag, msg);
    }

    public static void i(String tag, String msg)
    {
        if ( LOGGING_LEVEL >=3) Log.i(tag,msg);
    }

    public static void d(String tag, String msg)
    {
        if ( LOGGING_LEVEL >=4) Log.d(tag, msg);
    }

}