controller-legacy/include/logger.h

55 lines
1.5 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 _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_GREEN "[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_BLUE "[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_CYAN "[ 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_YELLOW "[ 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_RED "[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_MAGENTA "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_FATAL(msg, ...)
#endif
#endif //CONTROLLER_LOGGER_H