use __android_log_print() . You must include the header <android/log.h>
An example of an example. __android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "\n this is log messge \n");
You can also use a format specifier like printf -
__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "Need to print : %d %s",int_var, str_var);
Make sure you also link to the logging library in your Android.mk file:
LOCAL_LDLIBS := -llog
Oh .. forgot .. The output will be shown in Logcat with the LOG_TAG tag
Easy approach
Add the following lines to the general header file.
#include <android/log.h> #define LOG_TAG "your-log-tag" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) // If you want you can add other log definition for info, warning etc
Now just call LOGD("Hello world") or LOGE("Number = %d", any_int) as printf in c .
Remember to include a shared header file.
Delete log
If you define LOGD(...) empty, all logs will disappear. Just a comment after LOGD(...) .
#define LOGD(...) // __android_log..... rest of the code
Shaiful Apr 23 '12 at 5:25 2012-04-23 05:25
source share