gpt4 book ai didi

android - Android 的调试日志真的在运行时被剥离了吗?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:38:20 24 4
gpt4 key购买 nike

Android 文档 ( http://developer.android.com/reference/android/util/Log.html) 说:

Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept

我刚刚做了一个测试。在我的 Activity 中,我写道:

private static String test(String what) {
Log.e("test", "I am called with argument: " + what);
return what;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("test", "log level: " + test("v"));
Log.d("test", "log level: " + test("d"));
Log.i("test", "log level: " + test("i"));
Log.w("test", "log level: " + test("w"));
Log.e("test", "log level: " + test("e"));
}

我将我的项目导出为一个 apk 文件,然后我在我的手机上安装了这个 apk。我在手机上运行这个应用程序,然后查看日志。在那里,我看到函数测试被调用了五次,并且对 Log.something 函数的所有五次调用都导致其文本被写入日志。

那么 Log.d 调用真的在运行时被剥离了吗?

最佳答案

没有。你必须自己做。您可以像这样制作自己的 Log.d 包装器:

public static void debug(String tag, String msg) {
if (BuildConfig.DEBUG) {
Log.d(tag, msg);
}
}

关于android - Android 的调试日志真的在运行时被剥离了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15238450/

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