2012-08-06 45 views
2

我被卡住了,並在我的C代碼中的某個地方出現錯誤,我不知道在哪裏。我想用簡單的Log.i(tag, msg)Log.e(tag, msg)命令。我在網上查了一下,發現了其他兩個問題,但他們都沒有處理我正在說的話。我可以在我的C代碼中調用`Log。*`嗎?我想使用LogCat進行調試

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

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

如果在C++/C的語法是一樣的,我很抱歉,但我有兩個小經驗。

+2

你試過選項#2中的第二個問題,你聯繫?似乎到目前爲止最簡單的選擇。 'adb shell setprop log.redirect-stdio true' – 2012-08-06 18:32:08

回答

3

語法在C是同一

#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) 
+4

將'LOCAL_LDLIBS:= -llog'添加到你的make文件中...... – Frohnzie 2012-08-06 18:40:23

1
#include <cutils/log.h> 
#define LOG_TAG "MYDEBUG" 

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

在舊版本的宏是:

LOGD("Here we are!"); 
+0

這個日誌文件在哪裏?我也想知道ALOGD,ALOGE和ALOGI之間的區別... – 2014-09-05 14:05:48

+0

@ChefPharaoh ./system/core/include/cutils/log.h – 2014-10-22 10:21:09

+0

我更多的意思是這個日誌文件被保存或存儲在哪裏。但我想通過使用logcat和各種參數來查看我想要的日誌。雖然仍然會很高興知道這些日誌文件的存在位置。 – 2014-10-22 14:22:30

相關問題