You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add per-thread component/stream fields to log output (#314)
Log lines from long-running worker threads now carry a [component]
and, where applicable, a [stream] field between the level and the
message:
[timestamp] [LEVEL] [component] [stream] message ← stream threads
[timestamp] [LEVEL] [component] message ← non-stream threads
[timestamp] [LEVEL] message ← unchanged (API, etc.)
Implementation
──────────────
* Two __thread (TLS) char buffers are kept in logger.c.
* log_set_thread_context(component, stream) copies into them; no
mutex is needed — TLS is inherently per-thread.
* log_message_v() builds a ctx_prefix string from the TLS values and
prepends it to every text log line. When both buffers are empty
(the default) ctx_prefix is '' so existing behaviour is preserved.
* write_json_log() calls the new log_get_thread_component() /
log_get_thread_stream() getters and conditionally adds 'component'
and 'stream' fields to the JSON object, keeping the JSON schema
backward-compatible.
Public API additions in logger.h
─────────────────────────────────
void log_set_thread_context(component, stream_name)
void log_clear_thread_context(void)
const char *log_get_thread_component(void)
const char *log_get_thread_stream(void)
Thread contexts wired up
────────────────────────
MP4Writer mp4_writer_rtsp_thread (+ stream name)
MP4Recorder mp4_recording_thread (+ stream name)
HLSWriter hls_unified_thread_func (+ stream name)
Detection unified_detection_thread_func (+ stream name)
HLSWatchdog hls_watchdog_thread_func
StreamScheduler schedule_monitor_func
go2rtc unified_health_monitor_thread
RecordingSync sync_thread_func
MQTT ha_snapshot/motion/cleanup threads
HealthCheck health_check_thread_func
StorageManager unified_storage_controller_func
Closes #314
0 commit comments