How to print log messages with in Android framework

耗尽温柔 提交于 2019-12-01 19:13:15

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

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.

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).

doubleristretto

/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

First declare string

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

and than in your method

 Log.d(Tag,"This is my oncreate method");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!