summaryrefslogtreecommitdiffstats
path: root/src/reporting.h
diff options
context:
space:
mode:
authorAlex Dowad <alexinbeijing@gmail.com>2014-04-04 16:31:24 +0200
committerTimo Teräs <timo.teras@iki.fi>2014-04-25 10:16:30 +0300
commiteb5b69d278b1430750a5e1d74bd2804cbc4b14e8 (patch)
tree7a99d0443e7ac76478f47f777ef96e231983d88e /src/reporting.h
parent0ad83e2f69e69aeea1ac0baee108c4232449e36d (diff)
downloadsquark-eb5b69d278b1430750a5e1d74bd2804cbc4b14e8.tar.bz2
squark-eb5b69d278b1430750a5e1d74bd2804cbc4b14e8.tar.xz
all: unified framework for reporting errors/warnings/info messages to stderr/syslog
Diffstat (limited to 'src/reporting.h')
-rw-r--r--src/reporting.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/reporting.h b/src/reporting.h
new file mode 100644
index 0000000..c4f1c60
--- /dev/null
+++ b/src/reporting.h
@@ -0,0 +1,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 \ No newline at end of file