2

I am stuck and am getting an error somewhere within my C code, and I do not know where. I would like to use the simple Log.i( tag, msg ) or Log.e( tag, msg ) commands. I have looked around online and have found two other questions on SO but neither of them deal with exactly what I'm saying.

This method is not what I'm looking for...

And this is exactly what I'm looking for, but in C++, not C

If the syntax in C++/C is the same, I'm sorry but I have little experience in both.

Community
  • 1
  • 1
JuiCe
  • 4,132
  • 16
  • 68
  • 119
  • 2
    Have you tried option #2 in the second question you linked? Seems like by far the simplest option. `adb shell setprop log.redirect-stdio true` – Matt Ball Aug 06 '12 at 18:32

2 Answers2

3

Syntax in C is the same

#include <android/log.h>

#define TAG "MYDEBUG"

#ifdef DEBUG
#  define  D(x...)  __android_log_print(ANDROID_LOG_INFO, TAG , x)
#else
#  define  D(x...) do {} while (0)
#endif

#  define  W(x...)  __android_log_print(ANDROID_LOG_WARN, TAG , x)
#  define  E(x...)  __android_log_print(ANDROID_LOG_ERROR, TAG , x)
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
1
#include <cutils/log.h>
#define LOG_TAG "MYDEBUG"

...
ALOGD("Here we are!");

In older releases the macro was:

LOGD("Here we are!");
Valeri Atamaniouk
  • 5,125
  • 2
  • 16
  • 18
  • Where is this log file? I was also wondering the difference between ALOGD, ALOGE and ALOGI... – Chef Pharaoh Sep 05 '14 at 14:05
  • @ChefPharaoh ./system/core/include/cutils/log.h – Valeri Atamaniouk Oct 22 '14 at 10:21
  • I more meant where is this log file being kept or stored. But I figured out I can just use logcat with various arguments to see the log I desire. Although still would be nice to know where these log files live. – Chef Pharaoh Oct 22 '14 at 14:22
  • @ChefPharaoh The logs are not stored in files on the file system. Android documentation says "Logs from various applications and portions of the system are collected in a series of circular buffers" – Wextux May 22 '15 at 15:33