@setel/logger
v1.2.2
Published
This node package will help to send logs to SQS queue.
Downloads
3
Readme
logger
This node package will help to send logs to SQS queue.
Configuration (environment variables)
AWS_REGION
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
SQS_URL
Optional if not defined on making new instance of class
NODE_ENV
Initialization
const { Logger } = require('@setel/logger')
const logger = new Logger({
namespace: 'setel', // default: 'setel'
resource: 'api-x', // default: 'general'
version: '1.1.1', // default: ''
env: 'dev', // default: NODE_ENV
retry: false, // default: false
region: 'xx-xxxxxx-x', // default: process.env.AWS_REGION
awsKey: 'xxxxxxxx', // default: process.env.AWS_ACCESS_KEY_ID
awsSecret: 'xxxxxxxx', // default: process.env.AWS_SECRET_ACCESS_KEY
})
Sending log
await logger.log('Yaaa, it works', { response: { a: 'b' }})
Sending debug
await logger.debug('Some error exist here: ', { response: { a: 'b' }})
Sending error
await logger.error('Some error exist here: ', error)
Sending HTTP request/response from NestJS
Logger middleware: logger.middleware.ts
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';
import { Logger } from '@setel/logger';
const logger = new Logger({
namespace: 'setel-platform', // default: 'setel-platform'
resource: 'api-x', // default: 'general'
version: '1.1.1', // default: process.env.VERSION | '0.0.1'
env: 'dev', // default: process.env.NODE_ENV
retry: false, // default: false
region: 'xx-xxxxxx-x', // default: process.env.AWS_REGION
awsKey: 'xxxxxxxx', // default: process.env.AWS_ACCESS_KEY_ID
awsSecret: 'xxxxxxxx', // default: process.env.AWS_SECRET_ACCESS_KEY
})
@Injectable()
export class LoggerMiddleware implements NestMiddleware {
async use(req: Request, res: Response, next: Function) {
await log.http(req, res);
next();
}
}
Application Module
import { LoggerMiddleware } from './logger.middleware';
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(LoggerMiddleware)
.forRoutes({path: '*', method: RequestMethod.ALL});
}
}