-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.cpp
More file actions
74 lines (52 loc) · 1.4 KB
/
logger.cpp
File metadata and controls
74 lines (52 loc) · 1.4 KB
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
68
69
70
71
72
73
74
/**
* This file implements the Logging API specified in logger.h.
*/
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include "logger.h"
static enum log_level_e current_log_level = LOG_INFO; ///< Global variable defining the current log level.
void set_log_level(const enum log_level_e log_level) {
assert(log_level >= LOG_NONE);
current_log_level = log_level;
}
void log_message(const enum log_level_e log_level, const char* const message) {
assert(log_level > LOG_NONE);
assert(message != NULL);
if (log_level > current_log_level) {
return;
}
(void)fprintf(stderr, "%s\n", message);
}
void log_error(const char* const message) {
log_message(log_level_e::LOG_INFO, message);
}
void log_printf(const enum log_level_e log_level, const char* const format, ...) {
assert(log_level > LOG_NONE);
assert(format != NULL);
if (log_level > current_log_level) {
return;
}
va_list ap;
va_start(ap, format);
(void)vfprintf(stderr, format, ap);
va_end(ap);
(void)fputs("\n", stderr);
}
void log_printf_info(const char* const format, ...) {
va_list ap;
va_start(ap, format);
(void)vfprintf(stderr, format, ap);
va_end(ap);
(void)fputs("\n", stderr);
}
void log_printf_debug(const char* const format, ...) {
if (log_level_e::LOG_DEBUG > current_log_level) {
return;
}
va_list ap;
va_start(ap, format);
(void)vfprintf(stderr, format, ap);
va_end(ap);
(void)fputs("\n", stderr);
}