Dismiss
  • Scroll up
  • Toggle Theme
  • View as Mobile

@davidwells/smart-log

@davidwells/smart-log is a logging layer for command-line tools and automation scripts.

It supports normal user-facing logs, debug namespaces, JSON output for programmatic callers, silent mode, and log dumping for later inspection.

Why it matters

Good CLI tools need to be useful for humans and machines. The same command may need readable terminal output for a developer, structured JSON for another tool, or a complete debug log for a failing automation run.

What it includes

  • Debug namespaces controlled by DEBUG or --debug.
  • --silent mode for quiet automation.
  • --json output for downstream tools and agents.
  • Log dumping with ANSI-stripped or raw output.
  • Runtime toggles for silent, JSON, and debug behavior.
  • Optional console patching so existing console.log calls route through the same policy.

Install

npm install @davidwells/smart-log

Example

const { _console, debug, setJson } = require('@davidwells/smart-log')

const logHttp = debug('app:http')

_console.log('Starting job')
logHttp('request received')

setJson(true)
_console.json({ ok: true }, 'Result')