1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 09:58:26 +02:00

Adding a new file, debug.h, containing useful macros to output information:

DEBUG, INFO, WARNING, ERROR. The log level can be set using the LOG_LEVEL define.
This commit is contained in:
Ayla 2010-09-17 22:28:23 +02:00
parent 0775638dbc
commit 7d0c0e958c

77
src/debug.h Normal file
View File

@ -0,0 +1,77 @@
#ifndef DEBUG_H
#define DEBUG_H
#define NODEBUG_L 0
#define ERROR_L 1
#define WARNING_L 2
#define INFO_L 3
#define DEBUG_L 4
#ifndef LOG_LEVEL
#define LOG_LEVEL INFO_L
#endif
// -------------
#ifndef COLOR_DEBUG
#define COLOR_DEBUG "\e[0;34m"
#endif
#ifndef COLOR_WARNING
#define COLOR_WARNING "\e[01;33m"
#endif
#ifndef COLOR_ERROR
#define COLOR_ERROR "\e[01;31m"
#endif
#define COLOR_END "\e[0m"
#if (LOG_LEVEL >= DEBUG_L)
# ifdef COLOR_DEBUG
# define DEBUG(str, ...) \
fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, ##__VA_ARGS__)
# else
# define DEBUG(...) \
fprintf(stdout, "DEBUG: " __VA_ARGS__)
# endif
#else
#define DEBUG(...)
#endif
#if (LOG_LEVEL >= INFO_L)
# ifdef COLOR_INFO
# define INFO(str, ...) \
fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__)
# else
# define INFO(...) \
fprintf(stdout, __VA_ARGS__)
# endif
#else
#define INFO(...)
#endif
#if (LOG_LEVEL >= WARNING_L)
# ifdef COLOR_WARNING
# define WARNING(str, ...) \
fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END, ##__VA_ARGS__)
# else
# define WARNING(...) \
fprintf(stderr, "WARNING: " __VA_ARGS__)
# endif
#else
#define WARNING(...)
#endif
#if (LOG_LEVEL >= ERROR_L)
# ifdef COLOR_ERROR
# define ERROR(str, ...) \
fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, ##__VA_ARGS__)
# else
# define ERROR(...) \
fprintf(stderr, "ERROR: " __VA_ARGS__)
# endif
#else
#define ERROR(...)
#endif
#endif