如何在Android框架中打印日志消息
我正在尝试打印核心 Android 框架文件中的日志消息。例如,我尝试在 frameworks\base\media\libmediaplayerservice\
下的 MediaRecorderClient.cpp
中记录消息。我尝试过 LOGV、LOGE、LOGD、printf 和 __android_log_print没有任何成功。
我应该使用哪个命令来打印日志消息?
I am trying to print log messages within core Android framework files. For example, I tried logging messages within MediaRecorderClient.cpp
under frameworks\base\media\libmediaplayerservice\
. I've tried LOGV
, LOGE
, LOGD
, printf
, and __android_log_print
, without any success.
Which command should I use to print log messages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
应该使用日志,但它会打印到logcat而不是系统打印。
示例:
您可以在 Eclipse 中从 window-show view -> 打开 logcat其他->安卓->日志猫
Log should be used, but it will print to logcat not system print.
Example:
You can open logcat in eclipse from window-show view -> other -> android -> logcat
您收到什么样的错误?如果它无法编译,请确保您已在 Android.mk 中包含:
如果它编译但不产生任何输出,那么,就像 @Warpzit 所说,您必须查看logcat 查看您的消息。
What kind of error do you receive? If it does not compile, make sure you've included <android/log.h>, also in Android.mk:
If it compiles but does not produce any output, then, like @Warpzit has said, you have to look at logcat to see your messages.
似乎您只能将 char* 传递给 JNI LOG 方法。因此,如果调试字符串中有数字,则必须将它们放入字符缓冲区(使用 sprintf)。
It also seems that you can only pass a char* to the JNI LOG methods. So if you have numbers in your debug string, you have to put them into a char buffer (with sprintf).
/system/core/include/cutils/log.h
定义了用于在 Android 框架中进行日志记录的宏。因此,您取消注释源文件顶部的
#define LOG_NDEBUG 0
行,它将启用 VERBOSE 日志记录。您需要重新编译整个库并将其放入您的 android system.img 构建中。我相信宏调用是 ALOGV、ALOGE 等。
它类似于另一个答案:
如何在 logcat 中获取特定模块的详细日志记录
/system/core/include/cutils/log.h
defines the macros for logging in the Android Framework.So you uncomment the line that says
#define LOG_NDEBUG 0
at the top of the source file and it will enable VERBOSE logging. You will need to recompile that entire library and put it into your android system.img build.I believe the macro calls are ALOGV, ALOGE and so on.
It is similar to this other answer:
How to get Verbose logging in logcat for a specific module
声明 string和 not
首先在你的方法中
First declare string
and than in your method