open-card-table/oct_log.h

47 lines
1.2 KiB
C
Raw Normal View History

2023-05-23 10:59:37 -04:00
#ifndef OCT_LOG_H
#define OCT_LOG_H
#include <stdio.h>
#define OCT_LOG_LEVEL_ERROR 0
#define OCT_LOG_LEVEL_WARNING 1
#define OCT_LOG_LEVEL_INFO 2
#define OCT_LOG_LEVEL_DEBUG 3
extern FILE* oct_log_output_file;
extern int oct_log_level;
#define OCT_LOG_ERROR(...) \
if (oct_log_level >= OCT_LOG_LEVEL_ERROR) { \
fprintf(oct_log_output_file, "[ERR]: "); \
fprintf(oct_log_output_file, __VA_ARGS__); \
fprintf(oct_log_output_file, "\n"); \
}
#define OCT_LOG_WARNING(...) \
if (oct_log_level >= OCT_LOG_LEVEL_WARNING) { \
fprintf(oct_log_output_file, "[WAR]: "); \
fprintf(oct_log_output_file, __VA_ARGS__); \
fprintf(oct_log_output_file, "\n"); \
}
#define OCT_LOG_INFO(...) \
if (oct_log_level >= OCT_LOG_LEVEL_INFO) { \
fprintf(oct_log_output_file, "[INF]: "); \
fprintf(oct_log_output_file, __VA_ARGS__); \
fprintf(oct_log_output_file, "\n"); \
}
#define OCT_LOG_DEBUG(...) \
if (oct_log_level >= OCT_LOG_LEVEL_DEBUG) { \
fprintf(oct_log_output_file, "[DBG]: "); \
fprintf(oct_log_output_file, __VA_ARGS__); \
fprintf(oct_log_output_file, "\n"); \
}
// If filename is null, default to stderr
int oct_log_init(char* filename, int level);
int oct_log_deinit();
#endif