/* ckerrlog.h - Error report and logging for ck ------------------------*- C -*- * * This file is part of ck, the config keeper * * ----------------------------------------------------------------------------- * * Copyright (C) 2018 Anastasis Grammenos * GPLv3 (see LICENCE for the full notice) * * -------------------------------------------------------------------------- */ #ifndef CKERRLOG_H #define CKERRLOG_H #include #include #include #include #define CK_STREAMS \ X(err) \ X(log) \ X(logv) \ X(help) extern void initialize_errlog(int argc, char* argv[]); extern void report_errlog(); extern void errlog_set_verbose(int level); extern void ckerr(char *err, ...); extern void cklog(char *log, ...); extern void ckhelp(char *log, ...); #define X(stream) \ extern void ck## stream(char *log, ...); \ void ck## stream ##_with_delim(char *d, char *txt, ...); \ void report_## stream(); CK_STREAMS #undef X /**********/ /* Macros */ /**********/ /* define the component's name */ #define ERRLOG(_COMPONENT) \ static const char COMPONENT[STR_S] = #_COMPONENT #define ERR(...) \ ckerr_with_delim("\n", "Error in [%s]:", COMPONENT); \ ckerr(__VA_ARGS__); \ cklog_with_delim(" ", "ERROR: [%s]", COMPONENT); \ cklog(__VA_ARGS__); \ report_err(); /* Print help message */ #define HELP(...) \ ckhelp(__VA_ARGS__); \ report_help(); /* Log event */ #define LOG(...) \ cklog_with_delim(" ", "[%s]", COMPONENT); \ cklog(__VA_ARGS__); #define LOG_V(...) #endif /* CKERRLOG_H */