aboutsummaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
authorDavid Moc <personal@cdatgoose.org>2026-06-03 02:26:11 +0200
committerDavid Moc <personal@cdatgoose.org>2026-06-03 02:26:11 +0200
commitc6d44836fd8ed1442e01825cb0f9f97e7bf11515 (patch)
treed0e8cededdecafdf27476a744ac2d892d5a18620 /src/log.c
parentb68766967c86a6a789d65772f69f7f44939ebdf2 (diff)
Harden editor logging and packaging
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
index 7dec534..78c384a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -31,6 +31,22 @@ static char ecex_frame_group_start[1024];
static char ecex_frame_repeat_start[1024];
static char ecex_frame_repeat_end[1024];
static unsigned long ecex_frame_repeat_count = 0;
+static ecex_log_sink_fn ecex_log_sink = NULL;
+static void *ecex_log_sink_userdata = NULL;
+static int ecex_log_sink_active = 0;
+
+void ecex_log_set_sink(ecex_log_sink_fn fn, void *userdata) {
+ ecex_log_sink = fn;
+ ecex_log_sink_userdata = userdata;
+}
+
+void ecex_log_clear_sink(void *userdata) {
+ if (!userdata || userdata == ecex_log_sink_userdata) {
+ ecex_log_sink = NULL;
+ ecex_log_sink_userdata = NULL;
+ ecex_log_sink_active = 0;
+ }
+}
static size_t ecex_strn_copy(char *out, size_t out_cap, const char *in) {
size_t i = 0;
@@ -157,6 +173,12 @@ static void ecex_log_emit_raw_depth(const char *line, int depth) {
}
ecex_write_all(line ? line : "(null)", line ? len : 6);
ecex_write_all("\n", 1);
+
+ if (ecex_log_sink && !ecex_log_sink_active) {
+ ecex_log_sink_active = 1;
+ ecex_log_sink(line ? line : "(null)", depth, ecex_log_sink_userdata);
+ ecex_log_sink_active = 0;
+ }
}
static void ecex_log_emit_raw_counted(const char *line, int depth, unsigned long count) {