10.1_demo/include/e_logger.h

48 lines
1.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// e_logger.h
#ifndef E_LOGGER_H
#define E_LOGGER_H
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
// 日志级别定义
typedef enum
{
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR
} LogLevel;
// 初始化日志系统
void log_init(void);
// 设置日志级别
void log_set_level(LogLevel level);
// 设置日志输出文件
void log_set_output(FILE *output);
// 启用/禁用UDP日志发送
void log_set_udp_enabled(bool enabled);
// 设置UDP日志接收方IP地址成功返回true
bool log_set_udp_dest_ip(const char *ip);
// 打印日志
void log_print(LogLevel level, const char *file, int line, const char *format, ...);
// 清理日志资源
void log_cleanup(void);
// 删除日志文件
void log_delete_files(void);
// 日志宏定义(自动添加文件名和行号)
#define LOGD(format, ...) log_print(LOG_DEBUG, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define LOGI(format, ...) log_print(LOG_INFO, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define LOGW(format, ...) log_print(LOG_WARN, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define LOGE(format, ...) log_print(LOG_ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__)
#endif // E_LOGGER_H