linux c 编程 log输出

来源:互联网 发布:投诉淘宝店铺投诉电话 编辑:程序博客网 时间:2024/06/06 03:48

linux c 编程 log输出:

//printlog.h


#ifndef __PRINT_LOG__H__
#define __PRINT_LOG__H__

#include <time.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/types.h>

#define ZDBG(msg...)\  
do\ 
{\
struct timeval    tv;\  
struct timezone tz;\  
struct tm         *p;\  
gettimeofday(&tv, &tz);\  
p = localtime(&tv.tv_sec);\  
printf("[DBG:pid=%d tid=%d %d-%d:%d:%d.%ld]  ", getpid(), syscall(SYS_gettid),/*gettid(),*/ p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);\ 
printf("[\\\\\\ %s,%s, %d ///]---------------",__FILE__, __FUNCTION__, __LINE__);printf(msg);\
} while (0);


#define ZERR(msg...)\  
do\ 
{\
struct timeval    tv;\  
struct timezone tz;\  
struct tm         *p;\  
gettimeofday(&tv, &tz);\  
p = localtime(&tv.tv_sec);\  
printf("[ERR:%d-%d:%d:%d.%ld]  ", p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);\ 
printf("[\\\\\\ %s,%s, %d ///]!!!!!!!!!!!!!!!!!!!!---------------\n",__FILE__, __FUNCTION__, __LINE__);printf(msg);\
} while (0);


#endif

0 0