controller-legacy/include/logger.h

48 lines
1.3 KiB
C

#ifndef CONTROLLER_LOGGER_H
#define CONTROLLER_LOGGER_H
#include <stdio.h>
#include <colors.h>
#include <config.h>
#include <macros.h>
#define _LOGGER_MESSAGE(msg) COLOR_NONE " %s:%s:%d: " msg "\n", __FILENAME__, __func__, __LINE__
#if LOG_LEVEL >= LOG_LEVEL_TRACE
#define LOG_TRACE(msg, ...) printf(COLOR_GREEN "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_TRACE(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
#define LOG_DEBUG(msg, ...) printf(COLOR_BLUE "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_DEBUG(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_INFO
#define LOG_INFO(msg, ...) printf(COLOR_CYAN "[ INFO] " _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_INFO(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_WARN
#define LOG_WARN(msg, ...) printf(COLOR_YELLOW "[ WARN] " _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_WARN(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_ERROR
#define LOG_ERROR(msg, ...) printf(COLOR_RED "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_ERROR(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_FATAL
#define LOG_FATAL(msg, ...) printf(COLOR_MAGENTA "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else
#define LOG_FATAL(msg, ...)
#endif
#endif //CONTROLLER_LOGGER_H