如何在android C++文件中打印日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12152555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:53:55  来源:igfitidea点击:

How to print log in android c++ file?

androidlogging

提问by Victor S

I added

我加了

#define LOG_NDEBUG 0
#define LOG_TAG "StagefrightMediaScanner"
#include <utils/Log.h>

in the libstagefright/StagefrightMediaScanner.cpp

在里面 libstagefright/StagefrightMediaScanner.cpp

but can not print anything using LOGV and LOGE, does any other things can I need to do?

但无法使用 LOGV 和 LOGE 打印任何内容,我还需要做其他事情吗?

回答by Usman Kurd

You can use the following code to get Log

可以使用以下代码获取Log

  __android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "%s", Str);

and add the following header file

并添加以下头文件

#include <android/log.h>

回答by BonderWu

You can check frameworks/av/media/libstagefright/Android.mk, whether there is

可以查看frameworks/av/media/libstagefright/Android.mk,是否有

 LOCAL_SHARED_LIBRARIES += liblog

in it.

在里面。

Then, under frameworks/av/media/libstagefright/

然后,下 frameworks/av/media/libstagefright/

$ mm

$ adb push $OUT/system/lib/libstagefright.so /system/lib/ 

$ adb shell killall mediaserver 

Then reboot your phone or am start a MEDIA_MOUNTEDintent, MediaScanner will work, and the logs you just added(either ALOGE/ALOGVor LOGE/LOGV) should be shown.

然后重新启动您的手机或开始一个MEDIA_MOUNTED意图,MediaScanner 将工作,您刚刚添加的日志(ALOGE/ALOGVLOGE/LOGV)应该会显示出来。

回答by Tarun Chawla

No you have done right. Just check it whether you are using ALOGV() which is similar to printf(),if you want to print a integer with a log then you can write like this :" ALOGV("Integer is %d",integer);".

不,你做得对。只需检查您是否正在使用类似于 printf() 的 ALOGV(),如果您想打印一个带有日志的整数,那么您可以这样写:"ALOGV("Integer is %d",integer);"。