63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
#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
|
|
|
|
#define OCT_LOG_MAX_MESSAGE_LENGTH_LUA 1024
|
|
|
|
#include <lua5.3/lualib.h>
|
|
|
|
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();
|
|
|
|
// Logging on the C-side (oct_log_init) is initialized before lua
|
|
// Thus, we have to have a separate function for initializing logging on the
|
|
// lua-side that is called after lua is initialized
|
|
int oct_log_init_lua(lua_State* L);
|
|
|
|
// Can't call macros directly from lua, these are just wrapper functions
|
|
// for the above macros
|
|
int oct_log_error_lua(lua_State* L);
|
|
int oct_log_warning_lua(lua_State* L);
|
|
int oct_log_info_lua(lua_State* L);
|
|
int oct_log_debug_lua(lua_State* L);
|
|
|
|
#endif
|