logs.h
#ifndef _LOGS_H_
#define _LOHS_H_
#include <stdio.h>
#define DEBUG 1
#define _LTS_AM 1
#define _LTF_AM 0
#if DEBUG
#define DSPRINTF(cope,mesg,arg...) if(cope)printf(mesg,##arg);else
#define DFOPEN(cope,file,filename,arg) if(cope)file=fopen(filename,arg);else
#define DFPRINTF(cope,file,mesg,arg...) if(cope)fprintf(file,mesg,##arg);else
#define DFCLOSE(cope,file) if(cope)fclose(file);else
#else//DEBUG
#define DSPRINTF(cope,mesg,arg...)
#define DFOPEN(cope,file,filename,arg)
#define DFPRINTF(cope,file,mesg,arg...)
#define DFCLOSE(cope,file)
#endif
#endif//_LOGS_H_
logs.c
#include "logs.h"
#include <pthread.h>
void *thread_routine(void *arg)
{
int i;
FILE *threadfile;
DFOPEN(_LTF_AM,threadfile,"filet","a");
#if _LTF_AM
for(i=0;i<5;++i)
{
DFPRINTF(_LTF_AM,threadfile,"%d\n",i);
}
#endif
DFPRINTF(_LTF_AM,threadfile,"thread end\n");
DFPRINTF(_LTF_AM,threadfile,"%d\n",1);
DFPRINTF(_LTF_AM,threadfile,"%d+%d=%d\n",1,2,3);
DFCLOSE(_LTF_AM,threadfile);
}
int main()
{
int a=1;
if(a==1)
DSPRINTF(_LTS_AM,"Hello\n");
else
printf("error!\n");
DSPRINTF(_LTS_AM,"%d\n",1);
DSPRINTF(_LTS_AM,"%d+%d=%d\n\n",1,2,3);
pthread_t id;
int i;
FILE *mainfile;
pthread_create(&id,NULL,thread_routine,NULL);
DFOPEN(_LTF_AM,mainfile,"filem","a");
#if _LTF_AM
for(i=0;i<5;++i)
{
DFPRINTF(_LTF_AM,mainfile,"%d\n",i+1);
}
#endif
DFPRINTF(_LTF_AM,mainfile,"main end\n");
DFPRINTF(_LTF_AM,mainfile,"%d\n",1);
DFPRINTF(_LTF_AM,mainfile,"%d+%d=%d\n",1,2,3);
DFCLOSE(_LTF_AM,mainfile);
pthread_join(id,NULL);
printf("end.\n");
return 0;
}