-
Notifications
You must be signed in to change notification settings - Fork 0
/
clog.h
67 lines (55 loc) · 1.89 KB
/
clog.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* clog.h
* Copyright (C) 2020 Adrian Perez de Castro <aperez@igalia.com>
*
* Distributed under terms of the MIT license.
*/
#ifndef CLOG_H
#define CLOG_H
#include <stdbool.h>
#include <stdio.h>
enum clog_level {
CLOG_LEVEL_INFO,
CLOG_LEVEL_WARNING,
CLOG_LEVEL_ERROR,
CLOG_LEVEL_DEBUG,
};
extern bool clog_debug_enabled;
extern bool clog_fatal_errors;
extern bool clog_fatal_warnings;
extern void clog_init(const char *env_prefix);
extern void clog_format(enum clog_level,
const char *file,
unsigned line,
const char *func,
const char *fmt,
...);
#define clog_message(fmt, ...) \
fprintf(stderr, " ** " fmt "\n", ##__VA_ARGS__)
#define clog_info(fmt, ...) \
clog_format(CLOG_LEVEL_INFO, \
__FILE__, __LINE__, __func__, \
(fmt), ##__VA_ARGS__)
#define clog_warning(fmt, ...) \
clog_format(CLOG_LEVEL_WARNING, \
__FILE__, __LINE__, __func__, \
(fmt), ##__VA_ARGS__)
#define clog_error(fmt, ...) \
clog_format(CLOG_LEVEL_ERROR, \
__FILE__, __LINE__, __func__, \
(fmt), ##__VA_ARGS__)
#define clog_debug(fmt, ...) \
do { \
if (clog_debug_enabled) \
clog_format(CLOG_LEVEL_DEBUG, \
__FILE__, __LINE__, __func__, \
(fmt), ##__VA_ARGS__); \
} while (false)
#if defined(CLOG_SHORT_MACROS) && CLOG_SHORT_MACROS
#define cmessage clog_message
#define cinfo clog_info
#define cwarning clog_warning
#define cerror clog_error
#define cdebug clog_debug
#endif /* CLOG_SHORT_MACROS */
#endif /* !CLOG_H */