This module contains the "core" (API) of bemanitools which includes an abstraction layer for threads and logging at this time. The threads API is very close to what util/thread already was with some structural enhancements which make it easier to understand and work with the API, I hope. Some additional helpers (*-ext module) support in doing common tasks, e.g. setting up the thread API with other modules. The log(ging) part receives a major overhaul to address known limitations and issues with the util/log module: - Cleaner API layer - Separate sinks from actual logging engine - Sinks are composable - Improved and cleaner compatibility layer with AVS logging API Additional "extensions" (*-ext modules) add various helper functions for common tasks like setting up the logging engine with a file and stdout sink. The sinks also improved significantly with the file sink now supporting proper appending and log rotation. Logging to stdout/stderr supports coloring of log messages which works across logging engines. Overall, this refactored foundation is expected to support future developments and removes known limitations at the current scale of bemanitools such as: - Reducing boiler plate code across hooks - Interop of bemanitools and AVS (and setting the foundation for addressing currently missing interop, e.g. for dealing with property structures without AVS) - Addressing performance issues in the logging engine due to incorrect interop with AVS
67 lines
1.6 KiB
C
67 lines
1.6 KiB
C
#include <stdbool.h>
|
|
|
|
#include "core/log-bt.h"
|
|
#include "core/log-sink-debug.h"
|
|
#include "core/log-sink-file.h"
|
|
#include "core/log-sink-list.h"
|
|
#include "core/log-sink-mutex.h"
|
|
#include "core/log-sink-std.h"
|
|
#include "core/log.h"
|
|
|
|
void core_log_bt_ext_impl_set()
|
|
{
|
|
core_log_impl_set(
|
|
core_log_bt_log_misc,
|
|
core_log_bt_log_info,
|
|
core_log_bt_log_warning,
|
|
core_log_bt_log_fatal);
|
|
}
|
|
|
|
void core_log_bt_ext_init_with_stdout()
|
|
{
|
|
struct core_log_sink sink;
|
|
|
|
core_log_sink_std_out_open(true, &sink);
|
|
core_log_bt_init(&sink);
|
|
}
|
|
|
|
void core_log_bt_ext_init_with_stderr()
|
|
{
|
|
struct core_log_sink sink;
|
|
|
|
core_log_sink_std_err_open(true, &sink);
|
|
core_log_bt_init(&sink);
|
|
}
|
|
|
|
void core_log_bt_ext_init_with_debug()
|
|
{
|
|
struct core_log_sink sink;
|
|
|
|
core_log_sink_debug_open(&sink);
|
|
core_log_bt_init(&sink);
|
|
}
|
|
|
|
void core_log_bt_ext_init_with_file(
|
|
const char *path, bool append, bool rotate, uint8_t max_rotations)
|
|
{
|
|
struct core_log_sink sink;
|
|
|
|
core_log_sink_file_open(path, append, rotate, max_rotations, &sink);
|
|
core_log_bt_init(&sink);
|
|
}
|
|
|
|
void core_log_bt_ext_init_with_stdout_and_file(
|
|
const char *path, bool append, bool rotate, uint8_t max_rotations)
|
|
{
|
|
struct core_log_sink sinks[2];
|
|
struct core_log_sink sink_composed;
|
|
struct core_log_sink sink_mutex;
|
|
|
|
core_log_sink_std_out_open(true, &sinks[0]);
|
|
core_log_sink_file_open(path, append, rotate, max_rotations, &sinks[1]);
|
|
core_log_sink_list_open(sinks, 2, &sink_composed);
|
|
|
|
core_log_sink_mutex_open(&sink_composed, &sink_mutex);
|
|
|
|
core_log_bt_init(&sink_mutex);
|
|
} |