Skip to content

Add hierarchical log-category gates and enabled checks #187

Description

@codeforester

Problem

base-bash-libs currently uses one logger-level map for terminal visibility,
while BASE_CLI_PRIMARY_LOG independently persists the DEBUG stream. That
supports quiet terminals plus complete diagnostics, but it does not provide a
separate component/category gate. A consuming application therefore cannot
enable its own DEBUG output while explicitly declining reusable-library DEBUG
records, nor can it cheaply test whether an expensive library diagnostic would
reach any sink.

The existing -l <logger> support is exact-only and is not a hierarchical
category contract.

Goal

Add a backward-compatible category gate that is independent from terminal and
persistent sink thresholds.

Scope

  • Add set_log_category_level -l <category> <level>.
  • Resolve dotted categories in this order:
    1. exact category;
    2. nearest explicitly configured parent;
    3. the category default.
  • Keep the default category gate permissive through VERBOSE during the
    compatibility window so existing unscoped callers do not lose records.
  • Add log_is_enabled [-l <category>] <level>.
  • Require a record to pass its category gate before either the terminal or
    BASE_CLI_PRIMARY_LOG sink can consume it.
  • Keep set_log_level as the existing terminal-verbosity API.
  • Let unconfigured named terminal loggers inherit the default terminal level,
    while preserving explicit set_log_level -l <logger> <level> overrides.
  • Apply the same category and sink decisions to file logging helpers.
  • Document the public API and category-versus-sink model.

Acceptance criteria

  • Existing unscoped log_* and set_log_level behavior remains compatible.
  • Default INFO terminal output plus BASE_CLI_PRIMARY_LOG still persists
    unscoped DEBUG records without printing them.
  • Exact category configuration overrides a parent; a parent overrides
    default; sibling categories remain independent.
  • A category configured at INFO drops its DEBUG records from both stderr and
    BASE_CLI_PRIMARY_LOG.
  • A category configured at DEBUG with an INFO terminal and active primary sink
    persists DEBUG without printing it.
  • log_is_enabled returns success only when the category accepts the level and
    at least one configured sink would consume it.
  • log_is_enabled and set_log_category_level reject invalid levels and
    malformed -l usage without mutating existing state.
  • File logging helpers obey the same category gate.
  • Focused BATS tests and the complete repository validation pass.

Non-goals

  • Migrating the repository's own log calls to component categories.
  • Deprecating or removing VERBOSE.
  • Changing rendered log-record formatting.
  • Changing Base or Python logging behavior.
  • Changing VERSION or publishing a release.

Validation

  • Focused coverage in lib/bash/std/tests/lib_std.bats.
  • ./tests/validate.sh
  • git diff --check

Related work

Metadata

Metadata

Assignees

Labels

enhancementNew feature or product improvement

Type

No type

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions