1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * Copyright (C) 2014-2021 Paul Cercueil <paul@crapouillou.net>
19 #define LOG_LEVEL INFO_L
25 #define COLOR_DEBUG "\e[0;32m"
28 #define COLOR_WARNING "\e[01;35m"
31 #define COLOR_ERROR "\e[01;31m"
34 #define COLOR_END "\e[0m"
36 #if (LOG_LEVEL >= DEBUG_L)
38 # define pr_debug(str, ...) do { \
39 if (isatty(STDOUT_FILENO)) \
40 fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, \
43 fprintf(stdout, "DEBUG: " str, ##__VA_ARGS__); \
46 # define pr_debug(...) \
47 fprintf(stdout, "DEBUG: " __VA_ARGS__)
53 #if (LOG_LEVEL >= INFO_L)
55 # define pr_info(str, ...) \
56 fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__)
58 # define pr_info(...) \
59 fprintf(stdout, __VA_ARGS__)
65 #if (LOG_LEVEL >= WARNING_L)
67 # define pr_warn(str, ...) do { \
68 if (isatty(STDERR_FILENO)) \
69 fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END,\
72 fprintf(stderr, "WARNING: " str, ##__VA_ARGS__); \
75 # define pr_warn(...) \
76 fprintf(stderr, "WARNING: " __VA_ARGS__)
82 #if (LOG_LEVEL >= ERROR_L)
84 # define pr_err(str, ...) do { \
85 if (isatty(STDERR_FILENO)) \
86 fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, \
89 fprintf(stderr, "ERROR: " str, ##__VA_ARGS__); \
92 # define pr_err(...) \
93 fprintf(stderr, "ERROR: " __VA_ARGS__)