1.0.9 • Published 6 years ago

ezcodin-logger v1.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

EZCODIN-LOGGER

This is a very simple logger, that will allow you to console color coded debug statements, in addition to writing to log files. Currently three files are created info, warning, and error. Will be adding features over time.

Collaboraters welcome, looking forward to some pull requests!

VISIT: HOME PAGE

image

Install

> npm install ezcodin-logger

Setup

No Options:
const Log = require('ezcodin-logger')

//without callback or Options
let log = new Log()
With Callback:
const Log = require('ezcodin-logger')

//Optional Callback
let log = new Log( result => console.log(result))
With Options Object:
const Log = require('ezcodin-logger')

//Optional Options Object
let options = {
     colors:{
        error: 'red',
        warning: 'yellow',
        info: 'blue'
    },
    filePaths: {
        error: './logs/ez.error.log',
        warning: './logs/ez.warning.log',
        info: './logs/ez.info.log'
    }

}
let log = new Log( options)
All of the above:
const Log = require('ezcodin-logger')

//Optional Options Object
let options = {
     colors:{
        error: 'red',
        warning: 'yellow',
        info: 'blue'
    },
    filePaths: {
        error: './logs/ez.error.log',
        warning: './logs/ez.warning.log',
        info: './logs/ez.info.log'
    }

}

//With Options object and Callback
let log = new Log( options, result => console.log(result.msg)) //console => 'ezcodin-logger initialized'
# available colors: 
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray', 'redBright',
'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright'

Log to Console

//debug logger
log.debugError('debug error')
log.debugWarning('debug warning')
log.debugInfo('debug info')

alt text

Log to File

Log files are created in the root directory automatically upon instantiating the logger, use the options object to place logs in another location.

//Log to file
log.logError('log error')
log.logWarning('log warning')
log.logInfo('log info')

alt text

Express example

app.use(function (req, res, next) {
    let err = new Error(`${req.ip} tried to reach ${req.originalUrl}, resource not found`);
    err.statusCode = 404;
    log.logInfo(err.statusCode + err.message )
    res.status(err.statusCode).json({ status: err.statusCode, msg: err.message });
}); 

app.use(function(err, req, res, next) {
    if (!err.statusCode) err.statusCode = 500;   
    log.logError(err.statusCode + err.message )
    res.status(err.statusCode).json({ status: err.statusCode, msg: err.message }); 
    }
});
1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago