如何在Android框架中打印日志消息

发布于 2024-12-18 12:52:56 字数 229 浏览 5 评论 0原文

我正在尝试打印核心 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

与往事干杯 2024-12-25 12:52:56

应该使用日志,但它会打印到logcat而不是系统打印。

示例:

Log.d("filter", example text); // filter is any tag you want to use as filter

您可以在 Eclipse 中从 window-show view -> 打开 logcat其他->安卓->日志猫

Log should be used, but it will print to logcat not system print.

Example:

Log.d("filter", example text); // filter is any tag you want to use as filter

You can open logcat in eclipse from window-show view -> other -> android -> logcat

疑心病 2024-12-25 12:52:56

您收到什么样的错误?如果它无法编译,请确保您已在 Android.mk 中包含

LOCAL_LDLIBS := -llog

如果它编译但不产生任何输出,那么,就像 @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:

LOCAL_LDLIBS := -llog

If it compiles but does not produce any output, then, like @Warpzit has said, you have to look at logcat to see your messages.

瑾兮 2024-12-25 12:52:56

似乎您只能将 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).

写下不归期 2024-12-25 12:52:56

/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

棒棒糖 2024-12-25 12:52:56

声明 string和 not

Private String Tag = getClass().getsimplename();

首先在你的方法中

 Log.d(Tag,"This is my oncreate method");

First declare string

Private String Tag = getClass().getsimplename();

and than in your method

 Log.d(Tag,"This is my oncreate method");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文