- 重构模块使用新的代码风格 - 老代码 (src 目录下的代码) 继续使用之前的代码风格 通过在需要不同代码风格的目录下放对应 .clang-format 配置文件实现
42 lines
930 B
C
42 lines
930 B
C
#pragma once
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
|
|
#define fatal(format, ...) \
|
|
_fatal(__LINE__, __FUNCTION__, __FILE__, format, ##__VA_ARGS__)
|
|
void _fatal(
|
|
int line,
|
|
const char *function,
|
|
const char *file,
|
|
const char *format,
|
|
...
|
|
) __attribute__((noreturn)) __attribute__((format(printf, 4, 5)));
|
|
|
|
#define warn(format, ...) \
|
|
_warn(__LINE__, __FUNCTION__, __FILE__, format, ##__VA_ARGS__)
|
|
void _warn(
|
|
int line,
|
|
const char *function,
|
|
const char *file,
|
|
const char *format,
|
|
...
|
|
) __attribute__((format(printf, 4, 5)));
|
|
|
|
const char *current_time_str(void);
|
|
|
|
#if defined(RELEASE)
|
|
#define logger(format, ...)
|
|
#elif defined(LOG_FILE)
|
|
static inline void logger(const char *format, ...) {
|
|
va_list ap;
|
|
va_start(ap, format);
|
|
FILE *log_file = fopen(LOG_FILE, "a+t");
|
|
vfprintf(log_file, format, ap);
|
|
va_end(ap);
|
|
fclose(log_file);
|
|
}
|
|
#else
|
|
#define logger(format, ...) printf(format, ##__VA_ARGS__)
|
|
#endif
|