summaryrefslogtreecommitdiffstats
path: root/src/reporting.h
blob: c4f1c60de42d63ad95872e25e6e68df26ff419ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef REPORTING_H
#define REPORTING_H

/* message severity levels */
#define REPORT_ALERT   0
#define REPORT_ERROR   1
#define REPORT_WARNING 2
#define REPORT_INFO    3
#define REPORT_DEBUG   4

extern int verbosity_level;

void reporting_init(const char *program_name);
void reporting_use_syslog(int flag);
void reporting_verbosity(int level); /* setter */

/* rather than using report_message directly, use one of the below macros */
void report_message(int level, const char *format, ...);
void report_private_message(int level, const char *format, ...);

/* macros are used to minimize the performance impact of disabled (due to verbosity level) 'report' calls */
#define report_alert(format, ...)   if(REPORT_ALERT <= verbosity_level)   report_message(REPORT_ALERT, format, ##__VA_ARGS__)
#define report_error(format, ...)   if(REPORT_ERROR <= verbosity_level)   report_message(REPORT_ERROR, format, ##__VA_ARGS__)
#define report_warning(format, ...) if(REPORT_WARNING <= verbosity_level) report_message(REPORT_WARNING, format, ##__VA_ARGS__)
#define report_info(format, ...)    if(REPORT_INFO <= verbosity_level)    report_message(REPORT_INFO, format, ##__VA_ARGS__)
#define report_debug(format, ...)   if(REPORT_DEBUG <= verbosity_level)   report_message(REPORT_DEBUG, format, ##__VA_ARGS__)

#endif