controller-legacy/include/logger.h

63 lines
1.7 KiB
C
Raw Normal View History

2020-02-08 12:50:54 +00:00
#ifndef CONTROLLER_LOGGER_H
#define CONTROLLER_LOGGER_H
2020-02-09 23:58:17 +00:00
#include <stdio.h>
2020-04-13 22:50:55 +00:00
#include <time.h>
2020-02-23 00:13:27 +00:00
2020-02-08 12:50:54 +00:00
#include <colors.h>
#include <config.h>
#include <macros.h>
2020-04-13 23:51:40 +00:00
#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
2020-04-13 22:50:55 +00:00
#define _LOGGER_TIMESTAMP_SIZE 32
char _LOGGER_TIMESTAMP[_LOGGER_TIMESTAMP_SIZE];
char*
logger_get_timestamp();
2020-04-16 23:38:25 +00:00
#define _LOGGER_MESSAGE(msg) " %s %s:%d:%s: " COLOR_NONE msg "\n", logger_get_timestamp(), __FILENAME__, __LINE__, __func__
2020-02-08 12:50:54 +00:00
#if LOG_LEVEL >= LOG_LEVEL_TRACE
2020-04-13 23:51:40 +00:00
#define LOG_TRACE(msg, ...) fprintf(stdout, COLOR_TRACE "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
2020-02-08 12:50:54 +00:00
#else
#define LOG_TRACE(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
2020-04-13 23:51:40 +00:00
#define LOG_DEBUG(msg, ...) fprintf(stdout, COLOR_DEBUG "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
2020-02-08 12:50:54 +00:00
#else
#define LOG_DEBUG(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_INFO
2020-04-13 23:51:40 +00:00
#define LOG_INFO(msg, ...) fprintf(stdout, COLOR_INFO "[ INFO]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
2020-02-08 12:50:54 +00:00
#else
#define LOG_INFO(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_WARN
2020-04-13 23:51:40 +00:00
#define LOG_WARN(msg, ...) fprintf(stdout, COLOR_WARN "[ WARN]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
2020-02-08 12:50:54 +00:00
#else
#define LOG_WARN(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_ERROR
2020-04-13 23:51:40 +00:00
#define LOG_ERROR(msg, ...) fprintf(stderr, COLOR_ERROR "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
2020-02-08 12:50:54 +00:00
#else
#define LOG_ERROR(msg, ...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_FATAL
2020-04-13 23:51:40 +00:00
#define LOG_FATAL(msg, ...) fprintf(stderr, COLOR_FATAL "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
2020-02-08 12:50:54 +00:00
#else
#define LOG_FATAL(msg, ...)
#endif
#endif //CONTROLLER_LOGGER_H