]> git.ozlabs.org Git - ccan/blob - ccan/pr_log/pr_log.h
Makefile: Remove unused test targets
[ccan] / ccan / pr_log / pr_log.h
1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_PR_LOG_H_
3 #define CCAN_PR_LOG_H_
4
5 #include <stdbool.h>
6 #include <ccan/compiler/compiler.h>
7
8 /*
9  * pr_emerg, pr_alert, pr_crit, pr_error, pr_warn, pr_notice, pr_info, pr_debug
10  *
11  * Each of these prints a format string only in the case where we're running at
12  * the selected debug level.
13  *
14  * Note that using these functions also causes a pre-pended log level to be
15  * included in the printed string.
16  *
17  * Log levels correspond to those used in syslog(3) .
18  */
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__)
27
28 #ifdef DEBUG
29 # define pr_devel(...)  pr_debug(__VA_ARGS__)
30 #else
31 static PRINTF_FMT(1,2) inline void pr_check_printf_args(const char *fmt, ...)
32 {
33         (void)fmt;
34 }
35 # define pr_devel(...) pr_check_printf_args(__VA_ARGS__)
36 #endif
37
38 #ifndef CCAN_PR_LOG_DEFAULT_LEVEL
39 # define CCAN_PR_LOG_DEFAULT_LEVEL 6
40 #endif
41
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>"
50
51 #ifndef CCAN_PR_LOG_DISABLE
52 /**
53  * pr_log_ - print output based on the given logging level
54  *
55  * Example:
56  *
57  *      pr_log_(LOG_EMERG "something went terribly wrong\n");
58  *      pr_log_(LOG_DEBUG "everything is fine\n");
59  */
60 void PRINTF_FMT(1,2) pr_log_(char const *fmt, ...);
61 bool debug_is(int lvl);
62 int debug_level(void);
63 #else
64 static PRINTF_FMT(1,2) inline void pr_log_(char const *fmt, ...)
65 {
66         (void)fmt;
67 }
68 static inline bool debug_is(int lvl) { (void)lvl; return false; }
69 static inline int debug_level(void) { return -1; }
70 #endif
71
72 #endif