0.5.0 • Published 3 years ago
@clickout/logger v0.5.0
@clickout/logger
A simple logger with four channels: info
, error
, http
and rabbit
.
It uses a hybrid logging system that allows to show only minimal info on console and save more detailed data on elasticsearch.
Installation
npm install @clickout/logger
Usage
const Logger = require('@clickout/logger');
const logger = new Logger({
namespace: 'projectname',
application: 'appname',
transports: {
console: {
enabled: true,
format: 'minimal', // 'minimal' to print only the message, 'full' to print the entire log
exclude: ['http']
},
elasticsearch: {
enabled: true,
clientOpts: {
node: 'http://localhost:9200'
}
}
},
blacklist: ['accessToken']
});
logger.info('Preparing data...', { customer: { id: 52, email: 'nice@mail.com' }}, { elasticsearch: false });
logger.error('An error occurred', { error: new Error('Invalid parameter') });
logger.http('Http request received', { method: 'GET', url: '/' }, { console: false });
logger.rabbit('Received a new message', { message: { routingKey: 'customer.created', content: { id: 52 }}});
Logs are stored on elasticsearch using indexes in the following format logs-<namespace>-<level>-YYYY.MM
.
You can pass a third options parameter to disable console
or elasticsearch
logging for a specific log.
Use the blacklist
option to obscure certain properties with ********
.