Usage

About

I wanted to be able to have chattier daemons running in development, and more succinct logging in production but wanted to keep the simplicity of using console.log() etc.

Normally I pass in a granular verboseness level via arguments to control the verbosity level for the running process.

Installation

npm install --save verbosity

Examples

Simply override the built in console object:

import {createConsole} from 'verbosity'

const console = createConsole({
  outStream: process.stdout,
  errorStream: process.stderr,
  verbosity: 5
})

console.log('Works like normal...')
console.debug('...but now controllable.')

console.verbosity(3) // Use numbered levels 5 (debug) to 1 (error)

console.debug('...this isn’t printed now.')

console.canWrite(5) && console.dir({print: 'this won’t.'})

console.verbosity('debug') // Use named levels [debug, info, log, warning, error]

console.canWrite(5) && console.dir({print: 'this will now.'})

This will direct all console output to stderr, but silence 'info' and 'debug' messages.

import {createConsole} from 'verbosity'

const console = createConsole({
  outStream: process.stderr,
  verbosity: 3
})

console.log('Picked brown jacket...') // Printed
console.debug('Purple tie chosen...') // Not printed
console.warn("That tie doesn't go with that jacket.") // Printed

Or go mad with making up any number of custom console writers.

import {createConsole} from 'verbosity'

const myUberConsole = createConsole({
  outStream: myFancyWriteableStream,
  verbosity: 5
})

myUberConsole.panic('Core Flux Capacitor Meltdown!')

API

createConsole Verbosity

src/index.js

Create a new Verbosity object.

createConsole(options: object) → Verbosity
Parameters
options (object) Options to pass to the factory.
Returns
Verbosity: Verbosity's console object.

getVersion string

src/index.js

Return the modules version metadata.

getVersion(level: number) → string
Parameters
level (number) Version format required.
Returns
string: The version string.

Generate a verbosity console

new Verbosity(options: object) → Verbosity

Extends Console

Parameters
options (object = {}) Configuration options.
Name Description
options.outStream stream.writable Stream to write normal output
options.errorStream stream.writable Stream to write error output
options.verbosity number (default 3) The verboseness of output: 0: Mute 1: Errors 2: Notice 3: Log 4: Info 5: Debug
options.timestamp string Timestamp format.
options.namespace string Sparkles namespace to emit events to.
options.global boolean Should changes to verbosity be made globally?
options.prefix string Logging message prefix.
Returns
Verbosity: Verbosity's console object.
Instance Members
verbosity(level)
canWrite(level)
debug(message, args)
info(message, args)
log(message, args)
warn(message, args)
error(message, args)
critical(message, args)
panic(message, args)
emergency(message, args)
dir(object, options)
pretty(object, depth, color)
yargs(object, color)