- 论坛徽章:
- 0
|
#include <stdio.h>
#include <termio.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <sys/times.h>
//#define CONSOLE
/* the debug information will print on console */
#ifdef CONSOLE
#define DBFILE "/dev/console"
#define OPEN_FLAG "w"
#else
/* the debug information will write into file DBFILE */
#define DBFILE "./DB"
//#define DBFILE STDOUT
#define OPEN_FLAG "a+"
#endif
//Wed May 21 20:12:33 2008
#define DB(form_str,myargs...) \
do{\
if (1)\
{ \
char _buf[2048]={0};\
char _str_time[512];\
FILE *fFd=NULL;\
time_t time_file;\
time (&time_file); \
sscanf(ctime(&time_file),"%*s %*s %*s %s %*s",_str_time);\
snprintf (_buf,2048-1,form_str,##myargs);\
if(_buf[strlen(_buf)-1] == '\n') _buf[strlen(_buf)-1] ='\0';\
fFd=fopen(DBFILE,OPEN_FLAG); \
if ( fFd!=NULL )\
{\
fprintf(fFd,"%s: %s<== %s %s:%d\n",_str_time,_buf,__FILE__, __FUNCTION__,__LINE__);\
fclose(fFd);\
fFd=NULL;\
} \
}\
}while(0)
#define DB1() \
do{\
char _str_time[512];\
FILE *fFd=NULL;\
time_t time_file;\
time (&time_file); \
sscanf(ctime(&time_file),"%*s %*s %*s %s %*s",_str_time);\
fFd=fopen(DBFILE,OPEN_FLAG); \
if ( fFd!=NULL )\
{\
fprintf(fFd,"%s: %s %s:%d\n",_str_time,__FILE__, __FUNCTION__,__LINE__);\
fclose(fFd);\
fFd=NULL;\
}\
}while(0)
int main()
{
DB("test!");
DB1();
return 0;
} |
|