feat: Add helpers to easily setup the async logging sink

This commit is contained in:
icex2 2024-08-15 11:34:31 +02:00
parent a970884873
commit 3f4dab5fd6
2 changed files with 53 additions and 6 deletions

View File

@ -3,18 +3,24 @@
#include <stdbool.h>
#include "core/log-bt.h"
#include "core/log-sink-async.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"
// so we can log data dumps of rs232 streams without crashing
#define CORE_LOG_BT_EXT_MSG_BUFFER_SIZE 1024 * 64
// 64 kb * 64 = 4 MB for logging total
#define CORE_LOG_BT_EXT_ASYNC_QUEUE_LENGTH 64
void core_log_bt_ext_init_with_stdout()
{
core_log_sink_t sink;
core_log_sink_std_out_open(true, &sink);
core_log_bt_init(&sink);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink);
}
void core_log_bt_ext_init_with_stderr()
@ -22,7 +28,7 @@ void core_log_bt_ext_init_with_stderr()
core_log_sink_t sink;
core_log_sink_std_err_open(true, &sink);
core_log_bt_init(&sink);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink);
}
void core_log_bt_ext_init_with_debug()
@ -30,7 +36,7 @@ void core_log_bt_ext_init_with_debug()
core_log_sink_t sink;
core_log_sink_debug_open(&sink);
core_log_bt_init(&sink);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink);
}
void core_log_bt_ext_init_with_file(
@ -39,7 +45,7 @@ void core_log_bt_ext_init_with_file(
core_log_sink_t sink;
core_log_sink_file_open(path, append, rotate, max_rotations, &sink);
core_log_bt_init(&sink);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink);
}
void core_log_bt_ext_init_with_stdout_and_file(
@ -55,7 +61,7 @@ void core_log_bt_ext_init_with_stdout_and_file(
core_log_sink_mutex_open(&sink_composed, &sink_mutex);
core_log_bt_init(&sink_mutex);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink_mutex);
}
void core_log_bt_ext_init_with_stderr_and_file(
@ -71,5 +77,41 @@ void core_log_bt_ext_init_with_stderr_and_file(
core_log_sink_mutex_open(&sink_composed, &sink_mutex);
core_log_bt_init(&sink_mutex);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink_mutex);
}
void core_log_bt_ext_init_async_with_stderr()
{
core_log_sink_t sink;
core_log_sink_t sink_async;
core_log_sink_std_err_open(true, &sink);
core_log_sink_async_open(
CORE_LOG_BT_EXT_MSG_BUFFER_SIZE,
CORE_LOG_BT_EXT_ASYNC_QUEUE_LENGTH,
CORE_LOG_SINK_ASYNC_OVERFLOW_POLICY_DISCARD_NEW,
&sink, &sink_async);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink_async);
}
void core_log_bt_ext_init_async_with_stderr_and_file(
const char *path, bool append, bool rotate, uint8_t max_rotations)
{
core_log_sink_t sinks[2];
core_log_sink_t sink_composed;
core_log_sink_t sink_async;
core_log_sink_std_err_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_async_open(
CORE_LOG_BT_EXT_MSG_BUFFER_SIZE,
CORE_LOG_BT_EXT_ASYNC_QUEUE_LENGTH,
CORE_LOG_SINK_ASYNC_OVERFLOW_POLICY_DISCARD_NEW,
&sink_composed, &sink_async);
core_log_bt_init(CORE_LOG_BT_EXT_MSG_BUFFER_SIZE, &sink_async);
}

View File

@ -53,4 +53,9 @@ void core_log_bt_ext_init_with_stdout_and_file(
void core_log_bt_ext_init_with_stderr_and_file(
const char *path, bool append, bool rotate, uint8_t max_rotations);
void core_log_bt_ext_init_async_with_stderr();
void core_log_bt_ext_init_async_with_stderr_and_file(
const char *path, bool append, bool rotate, uint8_t max_rotations);
#endif