#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <errno.h>
int init_log(char *file_name, int file_size);
int write_log(const char *fmt, ...);
#define sys_log(format, args...) \
do \
{ \
write_log("%s(%d), %s:\n"format"\n", __FILE__, __LINE__, __FUNCTION__, ##args); \
} while (0)
#define sys_err_log(format, args...) \
do \
{ \
write_log("%s(%d), %s:\n"format":%s\n", __FILE__, __LINE__, __FUNCTION__, ##args, strerror(errno)); \
} while (0)
#define sys_err_log_quit(format, args...) \
do \
{ \
write_log("%s(%d), %s:\n"format":%s\n", __FILE__, __LINE__, __FUNCTION__, ##args, strerror(errno)); \
exit(1); \
} while (0)
#define DBG_PRINT(

这篇博客介绍了一个在Linux环境下使用C语言实现简单日志功能的代码,包括初始化日志、写入日志、错误日志处理等功能。通过定义宏实现不同级别的日志输出,并在日志文件达到指定大小时进行文件轮换。
最低0.47元/天 解锁文章
1214

被折叠的 条评论
为什么被折叠?



