logat
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/logat package

1.0.11 • Public • Published

logat npm version

a simple nodejs module for logging, provide many feature by default yet its coustomizable.

Available Features

  • Can log to FILE or CONSOLE.
  • Can print log name, date.
  • Can print lineNo, fileName and functionName for where the log method was called.
  • You can pass just string or object or any number of argument to log method.
  • All the object passed to log method will be stringify and will be prefix with Object{index}
  • If the object passed to error method is instance of error, then method will automatically print trace of that error, showing where the actuall error happend.
  • Will emit event "LogConfigError" if any error occured like wrong options or file read error etc, we can attach the event listener after importing the module
Please Note:

line number where log was called is different from line number where error object got instantianted. i.e

line1: var userError = new Error('user name is Invalid'); //line1 is where error got created
line2: logger.error(userError);     //line2 is where the one of the logger method was called

How to install

npm install logat

Basic Usages

let logger = require('logat')
logger.error('this is error');
logger.warn('this is warn');
logger.info('this is info');
logger.debug('this is debug');

Available Options with default value

options ={
    logLevel: 1-error, 2-warn, 3-info, 4-debug(default)
    logMethod: 1-Console(default), 2-File
    logFileName: 'app.log'(default)
}
Use logger.getOptions() method to get current options value;
Use logger.setOptions() method to set required options value;

Deatail Usages(example)

'use strict'
let logger = require('logat');

logger.on('LogConfigError', err => console.log(err) );

logger.setOptions({
    logLevel: 4,
    logMethod: 1
})

function getAge(age) {
    logger.debug('Inside Student function');
    if (age < 18) {
        throw new Error('age must be above 18')
    } else {
        logger.info('returned age: ', age);
    }
}

try {
    getAge(15);
} catch (e) {
    logger.error(e);
}

Deatail Usages(output of above example) alt tag

Example zip file

Example

Package Sidebar

Install

npm i logat

Weekly Downloads

16

Version

1.0.11

License

MIT

Unpacked Size

260 kB

Total Files

14

Last publish

Collaborators

  • krvikash35