forked from emersion/libliftoff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.c
42 lines (35 loc) · 934 Bytes
/
log.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
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "log.h"
static enum liftoff_log_importance log_importance = LIFTOFF_ERROR;
static void log_stderr(enum liftoff_log_importance verbosity, const char *fmt,
va_list args)
{
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
}
static liftoff_log_func log_callback = log_stderr;
void liftoff_log_init(enum liftoff_log_importance verbosity,
liftoff_log_func callback) {
log_importance = verbosity;
if (callback) {
log_callback = callback;
} else {
log_callback = log_stderr;
}
}
void liftoff_log(enum liftoff_log_importance verbosity, const char *fmt, ...)
{
if (verbosity > log_importance) {
return;
}
va_list args;
va_start(args, fmt);
log_callback(verbosity, fmt, args);
va_end(args);
}
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg)
{
liftoff_log(verbosity, "%s: %s", msg, strerror(errno));
}