konsol

    0.1.4 • Public • Published

    konsol

    License NPM Package NPM Downloads Build Status Test Coverage Code Climate Dependency Status devDependency Status

    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 konsol

    or

    $ npm install konsol --production

    for 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-user

    Although 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 Konsol for instance, this would be konsol.

    Example

      var konsol = require("konsol")("mymodule");
     
      konsol.log("The sky is blue.");
      //can also use .info, .warn, .error, .dir, .time, .timeEnd

    [static] 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 as
    KONSOL=mymodule yourmodule node app.js

    Tests

    Unit Tests

    $ npm test

    Unit Tests with Code Coverage

    $ npm run test-cov

    This 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-ci

    will 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-style

    will run the jscs stylechecker against the code.

    Static Code Analysis

    Executing

    $ npm run code-analysis

    will run jshint to analyse the code.

    Code Documentation

    Executing

    $ npm run make-docs

    will run jsdoc to create documentation.

    License

    MIT

    Install

    npm i konsol

    DownloadsWeekly Downloads

    1

    Version

    0.1.4

    License

    MIT

    Last publish

    Collaborators

    • kurt.pattyn