buffybox/shared/log.c

49 lines
810 B
C
Raw Normal View History

2021-09-23 21:05:36 +02:00
/**
* Copyright 2021 Johannes Marbach
* SPDX-License-Identifier: GPL-3.0-or-later
2021-09-23 21:05:36 +02:00
*/
2024-01-12 10:00:05 +01:00
2021-09-23 21:05:36 +02:00
#include "log.h"
#include <stdarg.h>
#include <stdio.h>
2021-09-25 14:34:54 +02:00
#include <string.h>
2021-09-23 21:05:36 +02:00
/**
* Static variables
*/
2024-03-30 20:52:01 +01:00
static bbx_log_level log_level = BBX_LOG_LEVEL_ERROR;
2021-09-23 21:05:36 +02:00
/**
* Public functions
*/
2024-03-30 20:52:01 +01:00
void bbx_log_set_level(bbx_log_level level) {
2021-09-23 21:05:36 +02:00
log_level = level;
}
2024-03-30 20:52:01 +01:00
void bbx_log(bbx_log_level level, const char *format, ...) {
2021-09-23 21:05:36 +02:00
if (level > log_level) {
return;
}
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
2021-09-25 14:34:54 +02:00
size_t l = strlen(format);
if (l > 0 && format[l - 1] != '\n') {
fprintf(stderr, "\n");
}
2021-09-23 21:05:36 +02:00
}
2024-03-30 20:52:01 +01:00
void bbx_log_print_cb(lv_log_level_t level, const char *msg) {
2024-01-25 09:59:45 +00:00
LV_UNUSED(level);
2024-03-30 20:52:01 +01:00
bbx_log(BBX_LOG_LEVEL_VERBOSE, msg);
2021-09-23 21:05:36 +02:00
}