1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
6 #include <ccan/compiler/compiler.h>
9 * pr_emerg, pr_alert, pr_crit, pr_error, pr_warn, pr_notice, pr_info, pr_debug
11 * Each of these prints a format string only in the case where we're running at
12 * the selected debug level.
14 * Note that using these functions also causes a pre-pended log level to be
15 * included in the printed string.
17 * Log levels correspond to those used in syslog(3) .
19 #define pr_emerg(...) pr_log_(LOG_EMERG __VA_ARGS__)
20 #define pr_alert(...) pr_log_(LOG_ALERT __VA_ARGS__)
21 #define pr_crit(...) pr_log_(LOG_CRIT __VA_ARGS__)
22 #define pr_error(...) pr_log_(LOG_ERROR __VA_ARGS__)
23 #define pr_warn(...) pr_log_(LOG_WARN __VA_ARGS__)
24 #define pr_notice(...) pr_log_(LOG_NOTICE __VA_ARGS__)
25 #define pr_info(...) pr_log_(LOG_INFO __VA_ARGS__)
26 #define pr_debug(...) pr_log_(LOG_DEBUG __VA_ARGS__)
29 # define pr_devel(...) pr_debug(__VA_ARGS__)
31 static PRINTF_FMT(1,2) inline void pr_check_printf_args(const char *fmt, ...)
35 # define pr_devel(...) pr_check_printf_args(__VA_ARGS__)
38 #ifndef CCAN_PR_LOG_DEFAULT_LEVEL
39 # define CCAN_PR_LOG_DEFAULT_LEVEL 6
42 #define LOG_EMERG "<0>"
43 #define LOG_ALERT "<1>"
44 #define LOG_CRIT "<2>"
45 #define LOG_ERROR "<3>"
46 #define LOG_WARN "<4>"
47 #define LOG_NOTICE "<5>"
48 #define LOG_INFO "<6>"
49 #define LOG_DEBUG "<7>"
51 #ifndef CCAN_PR_LOG_DISABLE
53 * pr_log_ - print output based on the given logging level
57 * pr_log_(LOG_EMERG "something went terribly wrong\n");
58 * pr_log_(LOG_DEBUG "everything is fine\n");
60 void PRINTF_FMT(1,2) pr_log_(char const *fmt, ...);
61 bool debug_is(int lvl);
62 int debug_level(void);
64 static PRINTF_FMT(1,2) inline void pr_log_(char const *fmt, ...)
68 static inline bool debug_is(int lvl) { (void)lvl; return false; }
69 static inline int debug_level(void) { return -1; }