Common-logger is a utility that takes a set of configuration parameters and returns a logger.
Common-logger currently supports two log types: Console
(stdout), File
(stream).
Run npm run generateReadme
to parse the code for JSDoc comment blocks and recreate this README.md file.
Run npm i @pillarwallet/common-logger
Instantiate a logger with default options (just writing out to Console):
@param level - (optional) set the level for a single output stream
@param name - (required) name of Log
@param path - (optional) Specify the file path to which log records are written
@param src - (optional - default false). Set true to enable 'src' automatic
field with log call source info
const buildLogger = require('@pillarwallet/common-logger');
const logger = buildLogger({ level: 'info', name: 'logTest', path: __dirname , src: false });
logger.info('Logger Info Hey!');
logger.warn('Logger Warn Hey!');
logger.fatal('Logger Fatal Hey!');
logger.error('Logger Error Hey!');
// with serializer
// "serializer" functions to produce a JSON-able object from a JavaScript object, so you can easily do the following:
const req = {
method: req.method,
url: req.url,
headers: req.headers
};
logger.info(req, 'Logger Info Test!');
To use HTTP request logger middleware, just follow the example:
const express = require('express');
const app = express();
app.use(logger.middleware());
Standard serializers are:
Field | Description |
---|---|
err | Used for serializing JavaScript error objects, including traversing an error's cause chain for error objects with a .cause() -- e.g. as from verror. |
req | Common fields from a node.js HTTP request object. |
res | Common fields from a node.js HTTP response object. |
- Constructor ⇒
This is the constructor of the Logger instance. It allows to set Configuration keys:
- middleware
use this method as middleware to log http requests.
- httpHeaderParser(string, begin, end) ⇒
string
Simple string parser
This is the constructor of the Logger instance. It allows to set Configuration keys:
Kind: global variable
Returns: Object
Param | Type | Description |
---|---|---|
name | String |
(required) name of Log |
level | String |
(optional) set the level for a single output stream |
path | String |
(optional) Specify the file path to which log records are written |
src | Boolean |
(optional) Defaults to false. Set true to enable 'src' automatic field with log call source info |
use this method as middleware to log http requests.
Kind: global variable
Param |
---|
req |
res |
next |
Simple string parser
Kind: global function
Param |
---|
string |
begin |
end |