1.0.4 • Published 7 years ago

log-handler-nt v1.0.4

Weekly downloads
2
License
ISC
Repository
gitlab
Last release
7 years ago

LogHandler

Module for logging in a NodeJS project. It is based on Winston (https://github.com/winstonjs/winston).

##Installation $ yarn install log-handler-nt --save

##Usage

###Configuration optionnal

You can set your own winston loggers with the function configure(winstonLoggers) See https://github.com/winstonjs/winston#working-with-multiple-loggers-in-winston for more details.

The configuration is optionnal, the module is using a default configuration.

configWinston.js

const winston = require('winston');
const appRootPath = require('app-root-path');


const options =
{
  fileProd:
  {
    level: 'info',
    filename: appRootPath+'/logs/app.log',
    format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
    maxsize: 5242880, // 5MB
    maxFiles: 5
  },

  consoleVerbose:
  {
    level: 'verbose',
    handleExceptions: true,
    format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
    colorize: true
  },

  consoleDebug:
  {
    level: 'debug',
    handleExceptions: true,
    format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
    colorize: true
  }
};

// PROD LOGGER
winston.loggers.add('production',
{
  transports: [new winston.transports.File(options.fileProd)],
  exitOnError: false
});

// DEV LOGGER
winston.loggers.add('dev',
{
  transports: [new winston.transports.Console(options.consoleVerbose)],
  exitOnError: false
});

// DEBUG LOGGER
winston.loggers.add('debug',
{
  transports: [new winston.transports.Console(options.consoleDebug)],
  exitOnError: false
});



module.exports = winston.loggers;

###Documentation

  • log(level, message, origin = "") @param level {string} level logging with priority

    	````json5
    	{ 

    error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }

    @param message {string|object} : Message to log<br>
    @param origin {string} : Optionnal 
  • stream.write Enable logging using stream.

  • track(module, arguments) @param module {id} : ID of the module @param arguments {callee: {name}}
1.0.4

7 years ago

1.0.3

7 years ago

0.5.3

7 years ago

1.0.2

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago