konsol v0.1.4
konsol
Author: Kurt Pattyn.
Konsol is a drop-in replacement for the node.js console. It adds the ability to enable and disable the output.
Suppression of the output can be controlled at run-time through the enable and disable static methods,
or at start-time through the use of the KONSOL environment variable.
Motivation
When using modules, one often wants to see debug output from those modules.
During normal operation these messages should not be shown. But during development these messages
can be very helpful for debugging.
Also during production it can be very helpful to be able to also get log output from included modules (e.g. in case of troubleshooting).
By using Konsol you can log messages just like with console from within your own modules, but Konsol adds the capability to enable or surpress
its output.
By default output is disabled.
Installation
$ npm install konsolor
$ npm install konsol --productionfor a production only installation (no tests, documentation, ...).
Usage
var konsol = require("konsol")("mymodule");
...
//we use konsol instead of console to do our logging
konsol.log("..."); //or info, warn, err, ...
module.exports = mymodule;Running node mymodule.js will generate no output (default behaviour).
When we run KONSOL=mymodule node mymodule.js the output will enabled and written the stdout.
Output can also programmatically enabled and disabled:
var Konsol = require("konsol");
Konsol.enable("mymodule");
var mm = require("mymodule");In the above example, the output of mymodule will be visible.
API
Konsol(moduleName)
Used in a (sub)module for logging. Registers moduleName with Konsol and returns a Konsol logger.
Parameters
moduleName(String, required): name of the module; this name should match the name by which the module is known to the end-userAlthough not strictly required, it is good practice to use the same name as the name by which the module is known to the end-user. In the case of
Konsolfor instance, this would bekonsol.
Example
var konsol = require("konsol")("mymodule");
konsol.log("The sky is blue.");
//can also use .info, .warn, .error, .dir, .time, .timeEndstatic Konsol.enable(moduleName)
Enables output for the given moduleName.
Parameters
moduleName(String, required): name of the module to enable output for
Example
var myModule = require("mymodule");
var Konsol = require("konsol");
Konsol.enable("mymodule");
//from now, all output of mymodule will be redirected to the console.static Konsol.disable(moduleName)
Disables output for the given moduleName.
Parameters
moduleName(String, required): name of the module to disable output for
Example
var myModule = require("mymodule");
var Konsol = require("konsol");
Konsol.disable("mymodule");
//from now, all output of Konsol will be suppressed.KONSOL Environment Variable
By default, all Konsol output is suppressed. Output can be enabled either by calling Konsol.enable() or
by setting the KONSOL environment variable.
E.g. calling Konsol.enable("mymodule") is the same as starting node with KONSOL=mymodule node myapp.js.
The difference between setting the KONSOL environment variable and calling Konsol.enable() is
that the enable() method can change the output at run-time.
The KONSOL environment variable is a comma- and/or space-separated list of modules for which
to enable the output.
E.g.KONSOL=mymodule, yourmodule node app.js
is the same asKONSOL=mymodule yourmodule node app.js
Tests
Unit Tests
$ npm testUnit Tests with Code Coverage
$ npm run test-covThis will generate a folder coverage containing coverage information and a folder coverage/lcov-report containing an HTML report with the coverage results.
$ npm run test-ciwill create a folder coverage containing lcov formatted coverage information to be consumed by a 3rd party coverage analysis tool. This script is typically used on a continuous integration server.
Checkstyle
Executing
$ npm run check-stylewill run the jscs stylechecker against the code.
Static Code Analysis
Executing
$ npm run code-analysiswill run jshint to analyse the code.
Code Documentation
Executing
$ npm run make-docswill run jsdoc to create documentation.