How to print log messages with in Android framework

前端 未结 5 878
清歌不尽
清歌不尽 2021-01-19 06:57

I am trying to print log messages within core Android framework files. For example, I tried logging messages within MediaRecorderClient.cpp under framewor

相关标签:
5条回答
  • 2021-01-19 07:09

    First declare string

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

    and than in your method

     Log.d(Tag,"This is my oncreate method");
    
    0 讨论(0)
  • 2021-01-19 07:12

    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.

    0 讨论(0)
  • 2021-01-19 07:15

    /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

    0 讨论(0)
  • 2021-01-19 07:30

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

    0 讨论(0)
  • 2021-01-19 07:34

    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

    0 讨论(0)
提交回复
热议问题