通过下面简单得代码可以控制Log得输出位置,是否输出
#ifndef LOG_H_INCLUDED
#define LOG_H_INCLUDED
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
int fd_log_file;
char g_msgFile[1024];
pthread_mutex_t log_info_mutex;
#define LOG_FILE_Path "/tmp/airtrek.log"
#define LOG_PRINT
#ifdef LOG_PRINT
#define print( fmt, args... ) \
printf("pid:%u %s "fmt, (unsigned int)pthread_self(), __func__ , ## args); \
#elif LOG_WRITE_FILE
#define print( fmt, args... )\
pthread_mutex_lock(&log_info_mutex);\
fd_log_file = open(LOG_FILE_Path,O_CREAT|O_WRONLY|O_APPEND);\
sprintf(g_msgFile,"pid:%u %s "fmt,(unsigned int)pthread_self(), __func__, ## args);\
write(fd_log_file,g_msgFile,strlen(g_msgFile));\
close(fd_log_file);\
pthread_mutex_unlock(&log_info_mutex);\
#else
#define print(fmt, args... )\
#endif
#endif // LOG_H_INCLUDED