diff options
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) { |
