Skip to content

feat(log): Read log level from the env#414

Closed
santanusinha wants to merge 2 commits into
DeusData:mainfrom
santanusinha:log-level-from-env
Closed

feat(log): Read log level from the env#414
santanusinha wants to merge 2 commits into
DeusData:mainfrom
santanusinha:log-level-from-env

Conversation

@santanusinha

Copy link
Copy Markdown

This PR closes #413.

Log level can be set at runtime using the CBM_LOG_LEVEL environment variable.

Allowed values:

  • Numeric:
    • 0 - DEBUG
    • 1 - INFO
    • 2 - WARN
    • 3 - ERROR
    • 4 - NONE
  • Textual:
    • DEBUG/debug - DEBUG
    • INFO/info - INFO
    • WARN/warn - WARN
    • ERROR/error - ERROR
    • NONE/none - NONE

Unknown values will be ignored and the system will stay at current behaviour.

Tests added and the README has been updated.

Note: cbm_log_init_from_env() is called on startup once before the first log statement.

Changes:

  • src/foundation/log.c: implement cbm_log_init_from_env()
  • src/foundation/log.h: declare cbm_log_init_from_env(); update comment
  • src/main.c: call cbm_log_init_from_env() early in main()
  • tests/test_log.c: add 5 test cases covering valid strings, case-insensitivity, unknown values, unset var, and numeric values
  • README.md: document CBM_LOG_LEVEL in the environment variables table

Log level can be set at runtime using the CBM_LOG_LEVEL
environment variable.

Allowed values:

- Numeric:
    - 0 - DEBUG
    - 1 - INFO
    - 2 - WARN
    - 3 - ERROR
    - 4 - NONE
- Textual:
    - DEBUG/debug - DEBUG
    - INFO/info - INFO
    - WARN/warn - WARN
    - ERROR/error - ERROR
    - NONE/none - NONE

Unknown values will be ignored and the system will stay at
current behaviour.

Tests added and the README has been updated.

Note: cbm_log_init_from_env() is called on startup once
before the first log statement.

Changes:
- src/foundation/log.c: implement cbm_log_init_from_env()
- src/foundation/log.h: declare cbm_log_init_from_env(); update comment
- src/main.c: call cbm_log_init_from_env() early in main()
- tests/test_log.c: add 5 test cases covering valid strings,
  case-insensitivity, unknown values, unset var, and numeric values
- README.md: document CBM_LOG_LEVEL in the environment variables table
DeusData added a commit that referenced this pull request Jun 6, 2026
…M_LOG_LEVEL

Two reviewed external-fork contributions, re-implemented as clean maintainer code.

#406 / PR #407 (thanks @nvt-pankajsharma): a POSIX parent-death watchdog so the stdio MCP server exits when its launching parent dies instead of lingering on stdin. Refactors signal_handler into an idempotent request_shutdown(); a watchdog thread polls getppid() (500ms) and shuts down + exit(0) once the initial ppid (>1) changes; Windows unaffected (#ifndef _WIN32). The fork's getppid()<=1 startup early-exit was dropped (it could wrongly kill a legitimately-launched server during reparent races / in container launchers; the initial_ppid>1 guard already no-ops safely), and thread-create failure is now non-fatal (matches the watcher/HTTP background-thread policy). Adds tests/test_parent_watchdog.sh + scripts/test.sh wiring.

#413 / PR #414 (thanks @santanusinha): runtime log-level control via CBM_LOG_LEVEL (case-insensitive debug|info|warn|error|none, or numeric 0..4; unset/unknown leaves the level unchanged). getenv() before threads start (no race). Adds tests/test_log.c cases + README env-var row.
@DeusData

DeusData commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Thank you, @santanusinhaCBM_LOG_LEVEL is a genuinely useful addition. I've distilled it into main (de1d58a): the env parsing (case-insensitive textual + numeric, fail-open), the README row, and the tests.

Closing in favor of the distilled commit. Thanks for the clean PR! 🙏

@DeusData DeusData closed this Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Read log level from the environment

2 participants