Package Exports
- verbosity
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (verbosity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Verbosity
An augmented drop-in console replacement that supports logging levels.
Install
npm install verbosity --save
Usage
Inside a single script, simply override the built in console object:
// This will duplicate the behaviour of the built in console object, with added logging levels.
console = require("verbosity").createConsole({
out: process.stdout
error: process.stderr
verbosity: 5
})
// The pre-v0.6.0 method is still available, but deprecated and will be removed in v1.0.0.
console = require("verbosity").console({
out: process.stdout
error: process.stderr
verbosity: 5
})
/*
This will direct all console output to stderr,
but silence 'info' and 'debug' messages.
*/
console = require("verbosity").createConsole({
out: process.stderr
verbosity: 3
})
// Or go mad with making up any number of custom console writers.
myUberConsole = require("verbosity").createConsole({
out: myFancyWriteableStream
verbosity: 5
})
To override the console object globally, in your main script (as coffeescript):
verbosity = require "verbosity"
global.vconsole = verbosity.createConsole
out: process.stderr
# You can then specify the override in each script's header.
console = global.vconsole
# Using the above pattern, you can also access verbosity helper methods.
verbosity.getVersion()
# Outputs 0.1.3-alpha.0
Full support of es2015 and rollup tree-shaking (jsnext:main points to optimised es2015 code)
import {createConsole} from 'verbosity'
console = createConsole({
out: process.stdout
error: process.stderr
verbosity: 5
})
API
The API inherits (prototypically) from Console, and all the argument parsing options are available.
(critical | panic | emergency) args... (level 1)
Write a Critical/Emergency/Panic error message in red. Best used just before aborting the process with a process.exit(1)
console.panic('Core Flux Capacitor Meltdown!')
$ CRITICAL: Core Flux Capacitor Meltdown!
error args... (level 1)
Write a normal error message in red.
console.error('This statement is false does not overload my logic circuits. moron.')
$ ERROR:This statement is false does not overload my logic circuits. moron.
warn args... (level 2)
Write a normal warning message in yellow.
console.warn("That tie doesn't go with that jacket.")
$ That tie doesn't go with that jacket.
log args... (level 3)
As console.log.
info args... (level 4)
As console.info.
debug args... (level 5)
Same and console.info, just a level lower.
dir object [options]
As console.dir, but defaults to colour and zero depth.
pretty object, depth
Pretty prints object, similar to OS X's plutil -p. Defaults to zero depth.
console.pretty(console)
/* Yeilds:
Object: VerbosityMatrix
critical ▸ [Function]
error ▸ [Function ▸ bound ]
warn ▸ [Function ▸ bound ]
log ▸ [Function ▸ bound ]
info ▸ [Function ▸ bound ]
debug ▸ [Function]
canWrite ▸ [Function]
...
*/
yargs object, depth
Helper function for pretty printing a summary of the current 'yargs' options.
Only prints 'long options', ._
as 'arguments' and $0
as 'self'.
console.yargs(yargs)
/* Yeilds:
Object (yargs):
left ▸ 2
right ▸ 2
mode ▸ 'hard'
encoding ▸ 'utf8'
...
self ▸ '/usr/local/bin/truwrap'
*/
canWrite level
Returns true if a message of level would be printed.
if (console.canWrite(5)) {
// Do something only if we're current logging at a debug level.
}
verbosity level
Set the current verbosity. The level will only stick if it's within the correct bounds. i.e 1-5.
time
As console.time.
timeEnd
As console.timeEnd.
trace
As console.trace.
assert
As console.assert.