2 * Copyright (C) 2014-2020 Paul Cercueil <paul@crapouillou.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
28 #define LOG_LEVEL INFO_L
34 #define COLOR_DEBUG "\e[0;32m"
37 #define COLOR_WARNING "\e[01;35m"
40 #define COLOR_ERROR "\e[01;31m"
43 #define COLOR_END "\e[0m"
45 #if (LOG_LEVEL >= DEBUG_L)
47 # define pr_debug(str, ...) do { \
48 if (isatty(STDOUT_FILENO)) \
49 fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, \
52 fprintf(stdout, "DEBUG: " str, ##__VA_ARGS__); \
55 # define pr_debug(...) \
56 fprintf(stdout, "DEBUG: " __VA_ARGS__)
62 #if (LOG_LEVEL >= INFO_L)
64 # define pr_info(str, ...) \
65 fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__)
67 # define pr_info(...) \
68 fprintf(stdout, __VA_ARGS__)
74 #if (LOG_LEVEL >= WARNING_L)
76 # define pr_warn(str, ...) do { \
77 if (isatty(STDERR_FILENO)) \
78 fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END,\
81 fprintf(stderr, "WARNING: " str, ##__VA_ARGS__); \
84 # define pr_warn(...) \
85 fprintf(stderr, "WARNING: " __VA_ARGS__)
91 #if (LOG_LEVEL >= ERROR_L)
93 # define pr_err(str, ...) do { \
94 if (isatty(STDERR_FILENO)) \
95 fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, \
98 fprintf(stderr, "ERROR: " str, ##__VA_ARGS__); \
101 # define pr_err(...) \
102 fprintf(stderr, "ERROR: " __VA_ARGS__)