/console-log-level-wrapper

A simple wrapper for the node.js console-log-level module.

Primary LanguageJavaScriptMIT LicenseMIT

console-log-level-wrapper

npm npm

Table of Contents

Introduction

This is a node.js wrapper module for the console-log-level node module, it's written in JavaScript.

But why this module?
This module helps to print simple logs, that based on an information level, in a customizable way. This pretty cool feature gives you the ability to show necessary informations in any projects, where you've to specify your logs.

Install

The module is currently available on github, so use the following command to install:

$ npm install https://github.com/MoonLiightz/console-log-level-wrapper/archive/v0.2.1.tar.gz --save

Usage

const logger = require('console-log-level-wrapper')({
    pattern: 'dd.mm.yyyy HH:MM:ss:l Z',
    level: 'trace'
});

logger.trace('trace');
logger.debug('debug');
logger.info('info');
logger.warn('warn');
logger.error('error');
logger.fatal('fatal');


// Output:

// [27.06.2017 12:55:10:891 GMT+0200][TRACE] trace
// [27.06.2017 12:55:10:902 GMT+0200][DEBUG] debug
// [27.06.2017 12:55:10:904 GMT+0200][INFO]  info
// [27.06.2017 12:55:10:904 GMT+0200][WARN]  warn
// [27.06.2017 12:55:10:904 GMT+0200][ERROR] error
// [27.06.2017 12:55:10:904 GMT+0200][FATAL] fatal

// Output if you changed level to 'info'

// [27.06.2017 12:55:10:904 GMT+0200][INFO]  info
// [27.06.2017 12:55:10:904 GMT+0200][WARN]  warn
// [27.06.2017 12:55:10:904 GMT+0200][ERROR] error
// [27.06.2017 12:55:10:904 GMT+0200][FATAL] fatal

TypeScript

import ConsoleLogLevelWrapper = require('console-log-level-wrapper');

const log = ConsoleLogLevelWrapper({
    pattern: 'dd.mm.yyyy HH:MM:ss:l Z',
    level: 'trace'
});

log.trace('trace');
log.debug('debug');
log.info('info');
log.warn('warn');
log.error('error');
log.fatal('fatal');

// ...

Options

pattern

A String to specify the date output. Look at node-dateformat for more input.

prefix

A String for an additional output. Look at examples/additional-prefix.js for an example.
It's optionally.

level

A Stringto specify the log level. Default: info

Examples

License

This project is licensed under the MIT License - see the LICENSE file for details.