Vorpal - Log
A Vorpal.js extension adding simple logging methods.
Installation
npm install vorpal-lognpm install vorpal
Getting Started
const vorpal = ;const vorpalLog = ; vorpal ; const logger = vorpallogger; vorpal action { logger; logger; logger; logger; logger; logger; logger; ;}; logger;logger;logger;
Default Functionality
Vorpal-log comes with the following predefined methods for logging:
logger.debug(msg)
(loglevel 10)logger.log(msg)
(loglevel 20)logger.info(msg)
(loglevel 20)logger.confirm(msg)
(loglevel 20)logger.warn(msg)
(loglevel 30)logger.error(msg)
(loglevel 40)logger.fatal(msg)
(loglevel 50)
logger.printMsg(msg)
will always print the message without caring about the loglevel or formatting.
Set the loglevel:
logger.setFilter(level)
E.g. logger.setFilter('warn')
will only print messages via logger.warn, logger.error and logger.fatal.
Options
The following options passed by vorpal.use(vorpalLogger, options)
are used:
printDate
: If this is true, the default formatters begin each message with the current date.preformat
: a function which is passed the message and which returns a string which should be logged instead by the default formatters. Could for example be used to render marked.
Commands
Vorpal-log adds the following (hidden) command, which simply delegates to logger.setFilter
. As a user can enable debug logging with it, you might want to remove it for production.
Usage: loglevel [options] <level>
set the log level
Options:
--help output usage information
Customizing
logger.addFormatter(name, level, format)
Creates a logger[name]
function, which will log the result of format(msg)
with loglevel level
. Use this to add custom formatters.
See customFormatter
here for a working, insightful and useful example.
logger.setFilter(filter)
Takes either a custom filter function, a string, or a number.
When logging something, the formatter is passed to the function set by logger.setFilter
. Logging only happens if this function returns true.
If logger.setFilter
is passed a function, this function is the new filter function.
If passed a number, the new filter function will only log, if formatter.level
is greater than or equal to that number.
If passed a string, the new filter function will only log if formatter.level
is greater than or equal to formatters[filter].level
.