Forgot to add log code
This commit is contained in:
parent
6a13c8d00e
commit
1576e64176
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include "oct_log.h"
|
||||
|
||||
FILE* oct_log_output_file;
|
||||
int oct_log_level;
|
||||
|
||||
// If filename is null, default to stderr
|
||||
int oct_log_init(char* filename, int level) {
|
||||
if (filename) {
|
||||
oct_log_output_file = fopen(filename, "w");
|
||||
}
|
||||
else {
|
||||
oct_log_output_file = stderr;
|
||||
}
|
||||
oct_log_level = level;
|
||||
|
||||
OCT_LOG_INFO("Initialized logging, output file: %s", filename ? filename : "stderr");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int oct_log_deinit() {
|
||||
if (oct_log_output_file != stderr) {
|
||||
fclose(oct_log_output_file);
|
||||
}
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#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
|
Loading…
Reference in New Issue