reqlog

1.1.3 • Public • Published

reqlog Build Status

A simple Node.js logger. Very closely attached to a request.

With Type Labels

Without Type Labels

It also supports a minimal profiling functionality to calculate the time from request start to end.

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install reqlog --save

Usage

var reqlog = require('reqlog');
reqlog.log('Endpoint', 'users/search');
reqlog.warn('UserSearch', 'NOT_FOUND');
reqlog.error('Internal Server Error', errorData);
reqlog.info('Success');

Complete example

var http = require('http');
var reqlog = require('reqlog');
 
reqlog.init(false);
 
var errorData = {
    database: {
        status: 'crashed'
    }
};
 
reqlog.log('Endpoint', 'users/search');
reqlog.warn('UserSearch', 'NOT_FOUND');
reqlog.error('Internal Server Error', errorData);
reqlog.info('Success');
 
var server = http.createServer(function(request, response) {
});
server.on('request', function(req, res) {
    reqlog.start(req, res);
    res.write('<html><body>Hello!</body></html>');
    res.end();
});
server.listen(3000, 'localhost');

API

init(typeLabels)

Type: boolean

Init method should be used on server start, to configure whether the logs should use typeLabels or not (check screenshots above)

log/warn/error/info (label, [data])

label

Type: string

A log label

data

Type: any
Default: false

Any data that you want to log alongside your label.
It can be of any type, and it's optional.

start(req, res)

req

Type: Object The request object

res

Type: Object The response object

It logs the request start, end and the time passed.

Tests

npm install
npm test

Dependencies

  • chalk: Terminal string styling done right. Much color.

Dev Dependencies

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i reqlog

Weekly Downloads

1

Version

1.1.3

License

MIT

Last publish

Collaborators

  • knorcedger