Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15531694
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2008-09-08 12:17:31

#include <stdio.h>

#define lU_DEBUG_PREFIX "##########"

#define LU_DEBUG_CMD 0x01
#define LU_DEBUG_DATA 0x02
#define LU_DEBUG_ERROR 0x04

#define LU_PRINTF_cmd(msg...) do{if(lu_debugs & LU_DEBUG_CMD)printf(lU_DEBUG_PREFIX msg);}while(0)
#define LU_PRINTF_data(msg...) do{if(lu_debugs & LU_DEBUG_DATA)printf(lU_DEBUG_PREFIX msg);}while(0)
#define LU_PRINTF_error(msg...) do{if(lu_debugs & LU_DEBUG_ERROR)printf(lU_DEBUG_PREFIX msg);}while(0)


#define lu_printf(level, msg...) LU_PRINTF_##level(msg)
#define lu_printf2(...) printf(__VA_ARGS__)
#define lu_printf3(...) lu_printf(__VA_ARGS__)
static int lu_printf4_format(int prio, const char *fmt, ...);
#define lu_printf4(prio, fmt...) lu_printf4_format(prio, fmt)


int lu_debugs;

int main(int argc, char *argv[])
{
    lu_debugs |= LU_DEBUG_CMD | LU_DEBUG_DATA | LU_DEBUG_ERROR;
    printf("lu_debugs = %p\n", lu_debugs);
    lu_printf(cmd,"this is cmd\n");
    lu_printf(data,"this is data\n");
    lu_printf(error,"this is error\n");
    lu_debugs &= ~(LU_DEBUG_CMD | LU_DEBUG_DATA);
    printf("lu_debugs = %p\n", lu_debugs);
    lu_printf(cmd,"this is cmd\n");
    lu_printf(data,"this is data\n");
    lu_printf(error,"this is error\n");
    lu_printf2("aa%d,%s,%dbbbbb\n", 20, "eeeeeee", 100);
    lu_debugs |= LU_DEBUG_CMD | LU_DEBUG_DATA | LU_DEBUG_ERROR;
    printf("lu_debugs = %p\n", lu_debugs);
    lu_printf3(cmd,"this is cmd \n");
    lu_printf3(data,"this is data\n");
    lu_printf3(error,"this is error\n");
    lu_printf4(0,"luther %s ,%d ,%d\n", "gliethttp", 1, 2);
    return 0;
}

#include <stdarg.h>
static int lu_printf4_format(int prio, const char *fmt, ...)
{
#define LOG_BUF_SIZE (4096)
    va_list ap;
    char buf[LOG_BUF_SIZE];

    va_start(ap, fmt);
    vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
    va_end(ap);

    printf("<%d>: %s", prio, buf);
    printf("------------------------\n");
    printf(buf);
}



#define ENTER() LOGD("enter into %s", __FUNCTION__)


#define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))

#define LOG(priority, tag, ...) \
    LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)

#define LOG_PRI(priority, tag, ...) \
    android_printLog(priority, tag, __VA_ARGS__)


#define android_printLog(prio, tag, fmt...) \
    __android_log_print(prio, tag, fmt)

阅读(10661) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-09-11 12:11:01

lu_printf("cfile=%s\n", cfile);

chinaunix网友2008-09-11 12:10:15

#define LU_PREFIX "======luther=" #define lu_printf(msg...) printf(LU_PREFIX msg) 这样就行,挺好用!