-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.c
45 lines (32 loc) · 978 Bytes
/
logger.c
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
/**
* 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_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);
}