1.0.7 • Published 7 years ago

n-logger v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

n-logger

We are defining the 4 levels of logging. Using this we can store the info, warn, debug, error of logs.

Installation

npm install n-logger

Example

'use strict';

var logger = require('n-logger');
logger.config({service : "Sample module",debug:false,info:true,warn:false,error:true})
var logStr = "Test";

logger.info("%s : This is info log.", logStr);
logger.warn("%s : This is warn log.", logStr);
logger.debug("%s : This is debug log.", logStr);
logger.error("%s : This is error log.", logStr);

Configuration

you can define the service name, and with log you want to activate that value should be 'false'. Bydefault all logs are active i.e. values are 'false'.

logger.config({
    service : "Sample module",
    debug:false,
    info:true,
    warn:false,
    error:true
    });

Dynamically you can enable or disable the logger level using following REST Interface,

app.post('/config', function (req, res) {
  console.log('Enable or disable logger dynamically');
  try {
    var configParams = req.body;
    console.log(configParams)
    /**
     * Set the configuration  
     */
    logger.config({
      service: "Sample module",
      debug: configParams.debug ? configParams.debug : false,
      info: configParams.info ? configParams.info : false,
      warn: configParams.warn ? configParams.warn : false,
      error: configParams.error ? configParams.error : false
    });
    return res.send('Success');
  } catch (err) {
    return res.status(500).json(err);
  }
});

REST API :

Method : POST 
URL : /config
Content-Type: application/json

Request : {"debug": true, "info": true, "warn": false, "error": true }
1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago