Any simple or easy way to log in Android NDK code?











up vote
59
down vote

favorite
14












I'm looking for a way to easily debug C code in an Android NDK application using Eclipse. I've read ways to debug the app using gdb or something similar but what I want is a way to push messages to Eclipse somehow.



I'm looking for a solution that's as simple as using a print function in C and seeing it in the DDMS Log or anything similar. Does anyone have any experience doing this?










share|improve this question




























    up vote
    59
    down vote

    favorite
    14












    I'm looking for a way to easily debug C code in an Android NDK application using Eclipse. I've read ways to debug the app using gdb or something similar but what I want is a way to push messages to Eclipse somehow.



    I'm looking for a solution that's as simple as using a print function in C and seeing it in the DDMS Log or anything similar. Does anyone have any experience doing this?










    share|improve this question


























      up vote
      59
      down vote

      favorite
      14









      up vote
      59
      down vote

      favorite
      14






      14





      I'm looking for a way to easily debug C code in an Android NDK application using Eclipse. I've read ways to debug the app using gdb or something similar but what I want is a way to push messages to Eclipse somehow.



      I'm looking for a solution that's as simple as using a print function in C and seeing it in the DDMS Log or anything similar. Does anyone have any experience doing this?










      share|improve this question















      I'm looking for a way to easily debug C code in an Android NDK application using Eclipse. I've read ways to debug the app using gdb or something similar but what I want is a way to push messages to Eclipse somehow.



      I'm looking for a solution that's as simple as using a print function in C and seeing it in the DDMS Log or anything similar. Does anyone have any experience doing this?







      android c eclipse jni android-ndk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 20:34









      Onik

      10.9k103760




      10.9k103760










      asked Jan 7 '11 at 19:11









      wajiw

      8,895174671




      8,895174671
























          6 Answers
          6






          active

          oldest

          votes

















          up vote
          112
          down vote



          accepted










          You can use the Android logging facilities:



          #include <android/log.h>

          #define APPNAME "MyApp"

          __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1);


          Make sure you also link against the logging library, in your Android.mk file:



            LOCAL_LDLIBS := -llog





          share|improve this answer

















          • 1




            If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
            – Sadegh Ghanbari
            Nov 1 '16 at 16:21


















          up vote
          12
          down vote













          The easiest way is probably to redirect printf() statements to the system log (based on the "Viewing stdout and stderr" section of the official ADB reference manual.



          Type these 3 commands on a command line:



          adb shell stop
          adb shell setprop log.redirect-stdio true
          adb shell start


          Then you can view the output of your "printf()" statements by looking at the "LogCat" window of Eclipse Debugger, or by typing this on a command line:



          adb logcat


          Just be aware that since the data is buffered before transferring from the emulator or device, you should definitely flush the stdout buffer, eg:



          printf("Hello, I am %d years old!n", 30);
          fflush(stdout);


          You should then see a log message starting with "I/stdout:"






          share|improve this answer



















          • 4




            Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
            – Sebastian Krysmanski
            May 10 '12 at 7:28










          • fflush has to be called after every printf statement?
            – Igor Ganapolsky
            Apr 12 '16 at 17:56


















          up vote
          2
          down vote













          An alternative solution (using a debugger) is explained here:



          How can I effectively debug C code that's wrapped with JNI in Eclipse? (Android Dev)






          share|improve this answer






























            up vote
            2
            down vote













            ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin. Instructions are pretty straightforward and consist of only a few steps.



            This is the simplest solution I found and it worked for me.



            Note: If you are using ADT bundle you only need to install C development tools with install new software (see the screenshot) and you can go to "Using the NDK plugin" part immediately.



            c dev tools install



            Edit: It seems there is an issue with CDT in eclipse juno http://code.google.com/p/android/issues/detail?id=33788 causing eclipse's debugger to be unable to find breakpoints.
            Workaround I used is to start app in debug mode (not debug as native app but 'regular' debug) and then in command line I went to my project root and typed ndk-gdb (this creates gdb.setup file in obj/local/armeabi folder). After that breakpoints worked as usual.



            In comments related to the issue on the link above they suggest some other workarounds but I didn't try them since they seemed to require more effort than this.






            share|improve this answer






























              up vote
              1
              down vote













              You can also a little util



              #include <android/log.h>

              #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-lib", __VA_ARGS__))


              Usage:



              std::string hello = "Hello from C++";
              int a = 1;
              LOGI("int %d, string: %s", a, hello.c_str());





              share|improve this answer




























                up vote
                0
                down vote













                No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.



                #include <android/log.h>

                #define TAG "MY_TAG"

                #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
                #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
                #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
                #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)


                Usage:



                LOGE("Something went wrong")


                Link Android log library as below.



                Android.mk:



                LOCAL_LDLIBS := -llog


                CMakeLists.txt:



                find_library( log-lib log )
                target_link_libraries( ${log-lib} )


                Further reading: Logging






                share|improve this answer





















                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                   

                  draft saved


                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4629308%2fany-simple-or-easy-way-to-log-in-android-ndk-code%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest
































                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  112
                  down vote



                  accepted










                  You can use the Android logging facilities:



                  #include <android/log.h>

                  #define APPNAME "MyApp"

                  __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1);


                  Make sure you also link against the logging library, in your Android.mk file:



                    LOCAL_LDLIBS := -llog





                  share|improve this answer

















                  • 1




                    If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
                    – Sadegh Ghanbari
                    Nov 1 '16 at 16:21















                  up vote
                  112
                  down vote



                  accepted










                  You can use the Android logging facilities:



                  #include <android/log.h>

                  #define APPNAME "MyApp"

                  __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1);


                  Make sure you also link against the logging library, in your Android.mk file:



                    LOCAL_LDLIBS := -llog





                  share|improve this answer

















                  • 1




                    If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
                    – Sadegh Ghanbari
                    Nov 1 '16 at 16:21













                  up vote
                  112
                  down vote



                  accepted







                  up vote
                  112
                  down vote



                  accepted






                  You can use the Android logging facilities:



                  #include <android/log.h>

                  #define APPNAME "MyApp"

                  __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1);


                  Make sure you also link against the logging library, in your Android.mk file:



                    LOCAL_LDLIBS := -llog





                  share|improve this answer












                  You can use the Android logging facilities:



                  #include <android/log.h>

                  #define APPNAME "MyApp"

                  __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1);


                  Make sure you also link against the logging library, in your Android.mk file:



                    LOCAL_LDLIBS := -llog






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 7 '11 at 20:03









                  svdree

                  11.3k42220




                  11.3k42220








                  • 1




                    If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
                    – Sadegh Ghanbari
                    Nov 1 '16 at 16:21














                  • 1




                    If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
                    – Sadegh Ghanbari
                    Nov 1 '16 at 16:21








                  1




                  1




                  If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
                  – Sadegh Ghanbari
                  Nov 1 '16 at 16:21




                  If using the new Gradle NDK integration in Android Studio (Gradle experimental), you need to add this line ldLibs.addAll(['android','log']) to your android.ndk options .
                  – Sadegh Ghanbari
                  Nov 1 '16 at 16:21












                  up vote
                  12
                  down vote













                  The easiest way is probably to redirect printf() statements to the system log (based on the "Viewing stdout and stderr" section of the official ADB reference manual.



                  Type these 3 commands on a command line:



                  adb shell stop
                  adb shell setprop log.redirect-stdio true
                  adb shell start


                  Then you can view the output of your "printf()" statements by looking at the "LogCat" window of Eclipse Debugger, or by typing this on a command line:



                  adb logcat


                  Just be aware that since the data is buffered before transferring from the emulator or device, you should definitely flush the stdout buffer, eg:



                  printf("Hello, I am %d years old!n", 30);
                  fflush(stdout);


                  You should then see a log message starting with "I/stdout:"






                  share|improve this answer



















                  • 4




                    Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
                    – Sebastian Krysmanski
                    May 10 '12 at 7:28










                  • fflush has to be called after every printf statement?
                    – Igor Ganapolsky
                    Apr 12 '16 at 17:56















                  up vote
                  12
                  down vote













                  The easiest way is probably to redirect printf() statements to the system log (based on the "Viewing stdout and stderr" section of the official ADB reference manual.



                  Type these 3 commands on a command line:



                  adb shell stop
                  adb shell setprop log.redirect-stdio true
                  adb shell start


                  Then you can view the output of your "printf()" statements by looking at the "LogCat" window of Eclipse Debugger, or by typing this on a command line:



                  adb logcat


                  Just be aware that since the data is buffered before transferring from the emulator or device, you should definitely flush the stdout buffer, eg:



                  printf("Hello, I am %d years old!n", 30);
                  fflush(stdout);


                  You should then see a log message starting with "I/stdout:"






                  share|improve this answer



















                  • 4




                    Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
                    – Sebastian Krysmanski
                    May 10 '12 at 7:28










                  • fflush has to be called after every printf statement?
                    – Igor Ganapolsky
                    Apr 12 '16 at 17:56













                  up vote
                  12
                  down vote










                  up vote
                  12
                  down vote









                  The easiest way is probably to redirect printf() statements to the system log (based on the "Viewing stdout and stderr" section of the official ADB reference manual.



                  Type these 3 commands on a command line:



                  adb shell stop
                  adb shell setprop log.redirect-stdio true
                  adb shell start


                  Then you can view the output of your "printf()" statements by looking at the "LogCat" window of Eclipse Debugger, or by typing this on a command line:



                  adb logcat


                  Just be aware that since the data is buffered before transferring from the emulator or device, you should definitely flush the stdout buffer, eg:



                  printf("Hello, I am %d years old!n", 30);
                  fflush(stdout);


                  You should then see a log message starting with "I/stdout:"






                  share|improve this answer














                  The easiest way is probably to redirect printf() statements to the system log (based on the "Viewing stdout and stderr" section of the official ADB reference manual.



                  Type these 3 commands on a command line:



                  adb shell stop
                  adb shell setprop log.redirect-stdio true
                  adb shell start


                  Then you can view the output of your "printf()" statements by looking at the "LogCat" window of Eclipse Debugger, or by typing this on a command line:



                  adb logcat


                  Just be aware that since the data is buffered before transferring from the emulator or device, you should definitely flush the stdout buffer, eg:



                  printf("Hello, I am %d years old!n", 30);
                  fflush(stdout);


                  You should then see a log message starting with "I/stdout:"







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 11 '11 at 8:28

























                  answered Aug 11 '11 at 6:32









                  Shervin Emami

                  2,2982017




                  2,2982017








                  • 4




                    Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
                    – Sebastian Krysmanski
                    May 10 '12 at 7:28










                  • fflush has to be called after every printf statement?
                    – Igor Ganapolsky
                    Apr 12 '16 at 17:56














                  • 4




                    Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
                    – Sebastian Krysmanski
                    May 10 '12 at 7:28










                  • fflush has to be called after every printf statement?
                    – Igor Ganapolsky
                    Apr 12 '16 at 17:56








                  4




                  4




                  Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
                  – Sebastian Krysmanski
                  May 10 '12 at 7:28




                  Note that this solution breaks JUnit tests. See: stackoverflow.com/questions/3462850/…
                  – Sebastian Krysmanski
                  May 10 '12 at 7:28












                  fflush has to be called after every printf statement?
                  – Igor Ganapolsky
                  Apr 12 '16 at 17:56




                  fflush has to be called after every printf statement?
                  – Igor Ganapolsky
                  Apr 12 '16 at 17:56










                  up vote
                  2
                  down vote













                  An alternative solution (using a debugger) is explained here:



                  How can I effectively debug C code that's wrapped with JNI in Eclipse? (Android Dev)






                  share|improve this answer



























                    up vote
                    2
                    down vote













                    An alternative solution (using a debugger) is explained here:



                    How can I effectively debug C code that's wrapped with JNI in Eclipse? (Android Dev)






                    share|improve this answer

























                      up vote
                      2
                      down vote










                      up vote
                      2
                      down vote









                      An alternative solution (using a debugger) is explained here:



                      How can I effectively debug C code that's wrapped with JNI in Eclipse? (Android Dev)






                      share|improve this answer














                      An alternative solution (using a debugger) is explained here:



                      How can I effectively debug C code that's wrapped with JNI in Eclipse? (Android Dev)







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 23 '17 at 12:26









                      Community

                      11




                      11










                      answered Feb 9 '11 at 8:05









                      Chris

                      3,34311615




                      3,34311615






















                          up vote
                          2
                          down vote













                          ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin. Instructions are pretty straightforward and consist of only a few steps.



                          This is the simplest solution I found and it worked for me.



                          Note: If you are using ADT bundle you only need to install C development tools with install new software (see the screenshot) and you can go to "Using the NDK plugin" part immediately.



                          c dev tools install



                          Edit: It seems there is an issue with CDT in eclipse juno http://code.google.com/p/android/issues/detail?id=33788 causing eclipse's debugger to be unable to find breakpoints.
                          Workaround I used is to start app in debug mode (not debug as native app but 'regular' debug) and then in command line I went to my project root and typed ndk-gdb (this creates gdb.setup file in obj/local/armeabi folder). After that breakpoints worked as usual.



                          In comments related to the issue on the link above they suggest some other workarounds but I didn't try them since they seemed to require more effort than this.






                          share|improve this answer



























                            up vote
                            2
                            down vote













                            ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin. Instructions are pretty straightforward and consist of only a few steps.



                            This is the simplest solution I found and it worked for me.



                            Note: If you are using ADT bundle you only need to install C development tools with install new software (see the screenshot) and you can go to "Using the NDK plugin" part immediately.



                            c dev tools install



                            Edit: It seems there is an issue with CDT in eclipse juno http://code.google.com/p/android/issues/detail?id=33788 causing eclipse's debugger to be unable to find breakpoints.
                            Workaround I used is to start app in debug mode (not debug as native app but 'regular' debug) and then in command line I went to my project root and typed ndk-gdb (this creates gdb.setup file in obj/local/armeabi folder). After that breakpoints worked as usual.



                            In comments related to the issue on the link above they suggest some other workarounds but I didn't try them since they seemed to require more effort than this.






                            share|improve this answer

























                              up vote
                              2
                              down vote










                              up vote
                              2
                              down vote









                              ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin. Instructions are pretty straightforward and consist of only a few steps.



                              This is the simplest solution I found and it worked for me.



                              Note: If you are using ADT bundle you only need to install C development tools with install new software (see the screenshot) and you can go to "Using the NDK plugin" part immediately.



                              c dev tools install



                              Edit: It seems there is an issue with CDT in eclipse juno http://code.google.com/p/android/issues/detail?id=33788 causing eclipse's debugger to be unable to find breakpoints.
                              Workaround I used is to start app in debug mode (not debug as native app but 'regular' debug) and then in command line I went to my project root and typed ndk-gdb (this creates gdb.setup file in obj/local/armeabi folder). After that breakpoints worked as usual.



                              In comments related to the issue on the link above they suggest some other workarounds but I didn't try them since they seemed to require more effort than this.






                              share|improve this answer














                              ADT 20 includes an NDK plugin that provides support for building and debugging NDK projects in Eclipse. This document describes how to install and use the NDK plugin. Instructions are pretty straightforward and consist of only a few steps.



                              This is the simplest solution I found and it worked for me.



                              Note: If you are using ADT bundle you only need to install C development tools with install new software (see the screenshot) and you can go to "Using the NDK plugin" part immediately.



                              c dev tools install



                              Edit: It seems there is an issue with CDT in eclipse juno http://code.google.com/p/android/issues/detail?id=33788 causing eclipse's debugger to be unable to find breakpoints.
                              Workaround I used is to start app in debug mode (not debug as native app but 'regular' debug) and then in command line I went to my project root and typed ndk-gdb (this creates gdb.setup file in obj/local/armeabi folder). After that breakpoints worked as usual.



                              In comments related to the issue on the link above they suggest some other workarounds but I didn't try them since they seemed to require more effort than this.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited May 7 '13 at 11:00

























                              answered May 3 '13 at 11:19









                              draganstankovic

                              3,84612027




                              3,84612027






















                                  up vote
                                  1
                                  down vote













                                  You can also a little util



                                  #include <android/log.h>

                                  #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-lib", __VA_ARGS__))


                                  Usage:



                                  std::string hello = "Hello from C++";
                                  int a = 1;
                                  LOGI("int %d, string: %s", a, hello.c_str());





                                  share|improve this answer

























                                    up vote
                                    1
                                    down vote













                                    You can also a little util



                                    #include <android/log.h>

                                    #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-lib", __VA_ARGS__))


                                    Usage:



                                    std::string hello = "Hello from C++";
                                    int a = 1;
                                    LOGI("int %d, string: %s", a, hello.c_str());





                                    share|improve this answer























                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote









                                      You can also a little util



                                      #include <android/log.h>

                                      #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-lib", __VA_ARGS__))


                                      Usage:



                                      std::string hello = "Hello from C++";
                                      int a = 1;
                                      LOGI("int %d, string: %s", a, hello.c_str());





                                      share|improve this answer












                                      You can also a little util



                                      #include <android/log.h>

                                      #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-lib", __VA_ARGS__))


                                      Usage:



                                      std::string hello = "Hello from C++";
                                      int a = 1;
                                      LOGI("int %d, string: %s", a, hello.c_str());






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 5 at 12:36









                                      Geng Jiawen

                                      3,9492526




                                      3,9492526






















                                          up vote
                                          0
                                          down vote













                                          No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.



                                          #include <android/log.h>

                                          #define TAG "MY_TAG"

                                          #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
                                          #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
                                          #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
                                          #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)


                                          Usage:



                                          LOGE("Something went wrong")


                                          Link Android log library as below.



                                          Android.mk:



                                          LOCAL_LDLIBS := -llog


                                          CMakeLists.txt:



                                          find_library( log-lib log )
                                          target_link_libraries( ${log-lib} )


                                          Further reading: Logging






                                          share|improve this answer

























                                            up vote
                                            0
                                            down vote













                                            No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.



                                            #include <android/log.h>

                                            #define TAG "MY_TAG"

                                            #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
                                            #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
                                            #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
                                            #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)


                                            Usage:



                                            LOGE("Something went wrong")


                                            Link Android log library as below.



                                            Android.mk:



                                            LOCAL_LDLIBS := -llog


                                            CMakeLists.txt:



                                            find_library( log-lib log )
                                            target_link_libraries( ${log-lib} )


                                            Further reading: Logging






                                            share|improve this answer























                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.



                                              #include <android/log.h>

                                              #define TAG "MY_TAG"

                                              #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
                                              #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
                                              #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
                                              #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)


                                              Usage:



                                              LOGE("Something went wrong")


                                              Link Android log library as below.



                                              Android.mk:



                                              LOCAL_LDLIBS := -llog


                                              CMakeLists.txt:



                                              find_library( log-lib log )
                                              target_link_libraries( ${log-lib} )


                                              Further reading: Logging






                                              share|improve this answer












                                              No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.



                                              #include <android/log.h>

                                              #define TAG "MY_TAG"

                                              #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
                                              #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
                                              #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
                                              #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)


                                              Usage:



                                              LOGE("Something went wrong")


                                              Link Android log library as below.



                                              Android.mk:



                                              LOCAL_LDLIBS := -llog


                                              CMakeLists.txt:



                                              find_library( log-lib log )
                                              target_link_libraries( ${log-lib} )


                                              Further reading: Logging







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 10 at 14:26









                                              Onik

                                              10.9k103760




                                              10.9k103760






























                                                   

                                                  draft saved


                                                  draft discarded



















































                                                   


                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4629308%2fany-simple-or-easy-way-to-log-in-android-ndk-code%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest




















































































                                                  Popular posts from this blog

                                                  Xamarin.iOS Cant Deploy on Iphone

                                                  Glorious Revolution

                                                  Dulmage-Mendelsohn matrix decomposition in Python