blob: 17c9d99a4a48e24689b50e5748dc6252d760e399 (
plain) (
blame)
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
|
/* Copyright (C) 2021-2021 Fuwn
* SPDX-License-Identifier: GPL-3.0-only */
#include <viv/log.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <viv/viv.h>
int VIV_LOG_log(VIV_LOG_level level, const char *format, ...) {
FILE *log_file;
char log_format[1024];
va_list arguments;
int print_result;
log_file = stdout;
if (level & VIV_LOG_level_TRACE) { strcpy(log_format, KMAG "[trace] " KNRM); }
else if (level & VIV_LOG_level_DEBUG) { strcpy(log_format, KCYN "[debug] " KNRM); }
else if (level & VIV_LOG_level_INFO) { strcpy(log_format, KGRN "[info] " KNRM); }
else if (level & VIV_LOG_level_WARN) {
strcpy(log_format, KYEL "[warn] " KNRM);
log_file = stderr;
} else if (level & VIV_LOG_level_ERROR) {
strcpy(log_format, KRED "[error] " KNRM);
log_file = stderr;
}
va_start(arguments, format);
print_result = vfprintf(log_file, strcat(log_format, format), arguments);
va_end(arguments);
if (level & VIV_LOG_level_ERROR) { VIV_exit(EXIT_FAILURE, NULL); }
return print_result;
}
|