62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
#ifndef CONTROLLER_LOGGER_H
|
|
#define CONTROLLER_LOGGER_H
|
|
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
#include <colors.h>
|
|
#include <config.h>
|
|
#include <macros.h>
|
|
|
|
#define COLOR_TRACE COLOR_GREEN
|
|
#define COLOR_DEBUG COLOR_BLUE
|
|
#define COLOR_INFO COLOR_CYAN
|
|
#define COLOR_WARN COLOR_YELLOW
|
|
#define COLOR_ERROR COLOR_RED
|
|
#define COLOR_FATAL COLOR_MAGENTA
|
|
|
|
#define _LOGGER_TIMESTAMP_SIZE 32
|
|
char _LOGGER_TIMESTAMP[_LOGGER_TIMESTAMP_SIZE];
|
|
|
|
char*
|
|
logger_get_timestamp();
|
|
|
|
#define _LOGGER_MESSAGE(msg) COLOR_NONE " %s %s:%d:%s: " msg "\n", logger_get_timestamp(), __FILENAME__, __LINE__, __func__
|
|
|
|
#if LOG_LEVEL >= LOG_LEVEL_TRACE
|
|
#define LOG_TRACE(msg, ...) fprintf(stdout, COLOR_TRACE "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
|
|
#else
|
|
#define LOG_TRACE(msg, ...)
|
|
#endif
|
|
|
|
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
|
|
#define LOG_DEBUG(msg, ...) fprintf(stdout, COLOR_DEBUG "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
|
|
#else
|
|
#define LOG_DEBUG(msg, ...)
|
|
#endif
|
|
|
|
#if LOG_LEVEL >= LOG_LEVEL_INFO
|
|
#define LOG_INFO(msg, ...) fprintf(stdout, COLOR_INFO "[ INFO]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
|
|
#else
|
|
#define LOG_INFO(msg, ...)
|
|
#endif
|
|
|
|
#if LOG_LEVEL >= LOG_LEVEL_WARN
|
|
#define LOG_WARN(msg, ...) fprintf(stdout, COLOR_WARN "[ WARN]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
|
|
#else
|
|
#define LOG_WARN(msg, ...)
|
|
#endif
|
|
|
|
#if LOG_LEVEL >= LOG_LEVEL_ERROR
|
|
#define LOG_ERROR(msg, ...) fprintf(stderr, COLOR_ERROR "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
|
|
#else
|
|
#define LOG_ERROR(msg, ...)
|
|
#endif
|
|
|
|
#if LOG_LEVEL >= LOG_LEVEL_FATAL
|
|
#define LOG_FATAL(msg, ...) fprintf(stderr, COLOR_FATAL "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
|
|
#else
|
|
#define LOG_FATAL(msg, ...)
|
|
#endif
|
|
|
|
#endif //CONTROLLER_LOGGER_H
|