diff options
| author | David Moc <personal@cdatgoose.org> | 2026-06-03 02:26:11 +0200 |
|---|---|---|
| committer | David Moc <personal@cdatgoose.org> | 2026-06-03 02:26:11 +0200 |
| commit | c6d44836fd8ed1442e01825cb0f9f97e7bf11515 (patch) | |
| tree | d0e8cededdecafdf27476a744ac2d892d5a18620 /src/log.c | |
| parent | b68766967c86a6a789d65772f69f7f44939ebdf2 (diff) | |
Harden editor logging and packaging
Diffstat (limited to 'src/log.c')
| -rw-r--r-- | src/log.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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) { |
