New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

reqlog

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reqlog

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

latest
Source
npmnpm
Version
1.1.3
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 20 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts