Skip to main content

Console

Runtime: Node.js; needs process in browsers — disableConsole reads process.env.NODE_ENV and clearConsole writes to process.stdout

Two blunt instruments for the console: clear it, or silence it. disableConsole replaces console.log with a no-op and only does so when NODE_ENV is production, so a stray debug log cannot leak into a shipped build while your local output stays intact. When you need the output back afterwards use logging's captureConsole, and for anything structured use logger.

Example​

import { disableConsole } from '@rtorcato/js-common/console'

// At the entry point of a shipped bundle.
disableConsole() // no-ops console.log, but only when NODE_ENV === 'production'

console.log('debug noise') // silent in prod, still printed locally

Only console.log is replaced — warn and error keep working, because silencing those in production is how incidents go unnoticed.

Import​

import { clearConsole, disableConsole } from '@rtorcato/js-common/console'

Exports​

NameSummary
clearConsoleClears the console.
disableConsoleDisables console output in production environment.

See also​

  • logging — leveled logging and console capture
  • logger — pre-configured Pino logger
  • env — read env vars and branch on NODE_ENV