Simplify split_args().
[dss.git] / log.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /** debug loglevel, gets really noisy */
4 #define DEBUG 1
5 /** still noisy, but won't fill your disk */
6 #define INFO  2
7 /** normal, but significant event */
8 #define NOTICE 3
9 /** unexpected event that can be handled */
10 #define WARNING 4
11 /** unhandled error condition */
12 #define ERROR 5
13 /** system might be unreliable */
14 #define CRIT 6
15 /** last message before exit */
16 #define EMERG 7
17
18 /** Log messages with lower priority than that will not be compiled in. */
19 #define COMPILE_TIME_LOGLEVEL 0
20
21 /** Not all compilers support __func__ or an equivalent. */
22 #if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__GNUC__)
23 # if defined(_MSC_VER) && _MSC_VER >= 1300
24 #  define __func__ __FUNCTION__
25 # else
26 #  define DSS_NO_FUNC_NAMES
27 #  define __func__ "<unknown>"
28 # endif
29 #endif
30
31 /** \cond */
32 #if DEBUG > COMPILE_TIME_LOGLEVEL
33 #define DSS_DEBUG_LOG(args) \
34         do { \
35                 dss_log_set_params(DEBUG, __FILE__, __LINE__, __func__); \
36                 dss_log args ; \
37         } while (0)
38 #else
39 #define DSS_DEBUG_LOG(args) do {;} while (0)
40 #endif
41
42 #if INFO > COMPILE_TIME_LOGLEVEL
43 #define DSS_INFO_LOG(args) \
44         do { \
45                 dss_log_set_params(INFO, __FILE__, __LINE__, __func__); \
46                 dss_log args ; \
47         } while (0)
48 #else
49 #define DSS_INFO_LOG(args) do {;} while (0)
50 #endif
51
52 #if NOTICE > COMPILE_TIME_LOGLEVEL
53 #define DSS_NOTICE_LOG(args) \
54         do { \
55                 dss_log_set_params(NOTICE, __FILE__, __LINE__, __func__); \
56                 dss_log args ; \
57         } while (0)
58 #else
59 #define DSS_NOTICE_LOG(args) do {;} while (0)
60 #endif
61
62 #if WARNING > COMPILE_TIME_LOGLEVEL
63 #define DSS_WARNING_LOG(args) \
64         do { \
65                 dss_log_set_params(WARNING, __FILE__, __LINE__, __func__); \
66                 dss_log args ; \
67         } while (0)
68 #else
69 #define DSS_WARNING_LOG(args) do {;} while (0)
70 #endif
71
72 #if ERROR > COMPILE_TIME_LOGLEVEL
73 #define DSS_ERROR_LOG(args) \
74         do { \
75                 dss_log_set_params(ERROR, __FILE__, __LINE__, __func__); \
76                 dss_log args ; \
77         } while (0)
78 #else
79 #define DSS_ERROR_LOG(args) do {;} while (0)
80 #endif
81
82 #if CRIT > COMPILE_TIME_LOGLEVEL
83 #define DSS_CRIT_LOG(args) \
84         do { \
85                 dss_log_set_params(CRIT, __FILE__, __LINE__, __func__); \
86                 dss_log args ; \
87         } while (0)
88 #else
89 #define DSS_CRIT_LOG(args) do {;} while (0)
90 #endif
91
92 #if EMERG > COMPILE_TIME_LOGLEVEL
93 #define DSS_EMERG_LOG(args) \
94         do { \
95                 dss_log_set_params(EMERG, __FILE__, __LINE__, __func__); \
96                 dss_log args ; \
97         } while (0)
98 #else
99 #define DSS_EMERG_LOG(args)
100 #endif