下面是之前编辑的一个自定义log的草稿,现在看着,对va_list的功能不大记得了,
当初应该也把它写清楚的,现在也懒的看了。
/*
* my log for trace code
*/
#ifndef MYLOG
#define MYLOG(...) \
MYLOG_PRINT(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define MYLOG_PRINT(prio, tag, fmt...) \
MYPRINT(prio, tag, fmt)
#define LOG_BUF_SIZE 1024
static long myNo = 0;
static int MYPRINT(int prio, const char *tag, const char *fmt, ...) {
va_list ap;
char *my_tag = "***It's My Log!*** No. ";
int len;
char buf[LOG_BUF_SIZE];
len = sprintf(buf, "%s%ld: ", my_tag, myNo++);
va_start(ap, fmt);
vsnprintf(buf+len, LOG_BUF_SIZE-len, fmt, ap);
va_end(ap);
return __android_log_write(prio, tag, buf);
}
#endif
/*
* end my log
*/