Skip to content

[Change] Add debug logs under ~/.specfact/logs with rich operation metadata #158

@djm81

Description

@djm81

Why

When --debug is enabled globally, users and developers need consistent debug logs to diagnose IO, file handling, and API issues. Today debug output is only printed to the console via debug_print() and is not persisted; there is no user-level log directory and no structured operation metadata (status, return, error) for file or API operations. Storing debug logs under ~/.specfact/logs and including rich operation metadata makes it possible to identify issues when something does not work as expected without cluttering normal CLI output.

What Changes

  • NEW: User-level debug log directory ~/.specfact/logs (create on first use when debug is enabled; mode 0o755). Add get_specfact_home_logs_dir() in logger_setup.py returning this path.
  • EXTEND: When --debug is set, route debug_print() output to both console (current) and a debug log file under ~/.specfact/logs (e.g. rotating specfact-debug.log).
  • NEW: Optional helper debug_log_operation(operation, target, status, error=None, extra=None) that no-ops when debug is off and when debug is on writes structured metadata to the debug log file and optionally calls debug_print().
  • EXTEND: In key places (file IO, API calls), when debug is on, log operation metadata: operation type, target (path/URL redacted), status/result, error snippet; use LoggerSetup.redact_secrets for any response/request bodies.
  • EXTEND: Adapters (ADO, GitHub) and commands (backlog refine, init) log file/API operation metadata when debug is enabled.
  • NOTE: get_runtime_logs_dir() remains unchanged for existing callers; ~/.specfact/logs is used only for the dedicated debug session log.

Acceptance Criteria

  • With --debug, a debug log file exists under ~/.specfact/logs and receives all debug_print() output plus structured operation metadata for file and API operations.
  • Without --debug, no ~/.specfact/logs directory is created and behavior is unchanged.
  • Secrets (tokens, keys) are redacted in debug logs (reuse LoggerSetup.redact_secrets).
  • CLI help for --debug mentions log location and purpose; CHANGELOG updated.

OpenSpec Change Proposal: add-debug-logs-specfact-home

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions