3.3 KiB
3.3 KiB
Didactyl Integration Plan: Unified nostr_core_lib Logging into One File
Goal
Route nostr_core_lib logs through didactyl logging so there is one authoritative file for errors, using existing didactyl logging in debug.c plus the new callback API in nostr_log.h.
Current State
- Didactyl writes logs to path from
DIDACTYL_LOG_FILEor defaultdebug.logindebug_open_log_file. - Didactyl log emission is centralized in
debug_log. - Relay pool setup occurs in
nostr_handler_init. nostr_core_libnow exposes callback logging API innostr_log.h.
Desired End State
nostr_core_liblogs are forwarded into didactyl logger via callback registration.- One file path configured by
DIDACTYL_LOG_FILEreceives didactyl plus nostr_core_lib errors. - Log lines preserve source component tags such as
nostr:websocketandnostr:nip013.
Architecture
flowchart TD
A[nostr_core_lib emits callback log] --> B[didactyl bridge callback in nostr_handler.c]
B --> C[map nostr level to didactyl level]
C --> D[debug_log in debug.c]
D --> E[DIDACTYL_LOG_FILE single destination]
Implementation Steps
-
Add bridge function in
nostr_handler.c- Create static callback
nostr_core_log_bridge level component message user_data. - Prefix forwarded lines with
nostr:namespace.
- Create static callback
-
Map levels from
nostr_core_libto didactylNOSTR_LOG_LEVEL_ERRORtoDEBUG_LEVEL_ERRORNOSTR_LOG_LEVEL_WARNtoDEBUG_LEVEL_WARNNOSTR_LOG_LEVEL_INFOtoDEBUG_LEVEL_INFONOSTR_LOG_LEVEL_DEBUGtoDEBUG_LEVEL_DEBUGNOSTR_LOG_LEVEL_TRACEtoDEBUG_LEVEL_TRACE
-
Register callback during startup in
nostr_handler_init- Before relay setup, call
nostr_set_log_callback. - Set threshold with
nostr_set_log_levelaligned to current didactyl debug level.
- Before relay setup, call
-
Enforce single-file policy
- Set
DIDACTYL_LOG_FILEto desired final log path. - Keep didactyl as only file owner via
debug_open_log_file.
- Set
-
Ensure error visibility
- Keep bridge forwarding at least error and warn levels even when app runs at lower verbosity.
- Optionally pin library threshold to
WARNorERRORfor production profiles.
Validation Plan
-
Start didactyl with explicit file path
- Example environment:
DIDACTYL_LOG_FILE=didactyl.log.
- Example environment:
-
Trigger nostr websocket activity
- Confirm
nostr:websocketentries appear in same file.
- Confirm
-
Trigger nip013 path
- Confirm
nostr:nip013entries appear in same file.
- Confirm
-
Trigger normal didactyl LLM call
- Confirm
[didactyl] llm requeststill lands in same file.
- Confirm
-
Verify there is no second active file for nostr core logs.
Rollout Notes
- Implement bridge first, then verify in development run.
- If log volume is too high, reduce callback threshold by setting
nostr_set_log_level. - Keep one destination file operationally stable by configuring and documenting
DIDACTYL_LOG_FILE.
Files to Change in Code Mode
src/nostr_handler.c- Optional docs update in
README.md - Optional operational note in
docs/TOOLS.md