aboutsummaryrefslogtreecommitdiffstats
path: root/src/ckerrlog.h
blob: d3d724338e6a88425f0f666f03585825c26e7916 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* 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 <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>

#define CK_STREAMS                              \
  X(err)                                        \
  X(log)                                        \
  X(help)                                     

void ckerr_add_component(char *txt, ...);

extern void initialize_errlog();
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, ...);
extern void report_err();
extern void report_help();

/**********/
/* Macros */
/**********/

/* define the component's name */
#define ERRLOG(_COMPONENT)                              \
  static const char COMPONENT[STR_S] = #_COMPONENT

#define ERR(...)                                    \
  ckerr("Error in [%s]:", COMPONENT); \
  ckerr(__VA_ARGS__);                               \
  report_err();                                 

#endif /* CKERRLOG_H */