-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.h
66 lines (57 loc) · 1.19 KB
/
logger.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
/*
* Vectorix -- line-based image vectorizer
* (c) 2016 Jan Hadrava <[email protected]>
*/
#ifndef VECTORIX__LOGGER_H
#define VECTORIX__LOGGER_H
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include "config.h"
// LOGGER
namespace vectorix {
enum class log_level {
error = 0,
warning = 1,
info = 2,
debug = 3
};
class logger {
public:
logger() = default;
logger(log_level verbosity): verbosity_(verbosity) {};
void set_verbosity(log_level verbosity) {
verbosity_ = verbosity;
}
template <log_level L> void log(const char *format, ...) {
if (L <= VECTORIX_MAX_VERBOSITY) {
if (L <= verbosity_) {
switch (L) {
case log_level::error:
fprintf(stderr, "<Error>: ");
break;
case log_level::warning:
fprintf(stderr, "<Warning>: ");
break;
case log_level::info:
fprintf(stderr, "<Info>: ");
break;
case log_level::debug:
fprintf(stderr, "<Debug>: ");
break;
default:
fprintf(stderr, "<Unknown>: ");
break;
}
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
}
};
private:
log_level verbosity_;
};
}; // namespace
#endif