#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
/* 附加两种方式的宏定义 */
//#define dev_debug(level, module, format...) syslog(level, module, ##format)
//#define dev_debug(level, module, format, ...) syslog(level, format, module, ##__VA_ARGS__)
void debug_print(va_list va, char *format, int level, char *module)
{
char buffer[1024];
struct tm tm_time;
time_t curtime;
char ctime[32];
memset(buffer, 0, sizeof(buffer));
vsnprintf(buffer, sizeof(buffer), format, va);
curtime = time(NULL);
memset(&tm_time, 0, sizeof(tm_time));
localtime_r(&curtime, &tm_time);
memset(&ctime, 0, sizeof(ctime));
sprintf(ctime, "%04d-%02d-%02d %02d:%02d:%02d",
tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday,
tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
/* 自定义输出格式 */
printf("[%s][%s] %s\n", ctime, module, buffer);
}
void syslog(int level, char *module, char *format, ...)
{
va_list args;
va_start(args, format);
debug_print(args, format, level, module);
va_end(args);
}
int main(int argc, char **argv)
{
syslog(1, "test", "%s %d", __FUNCTION__, __LINE__);
return 0;
}