@awasthishiva/nestjs-log
v1.0.2
Published
NestJS logger
Downloads
31
Readme
Installation
npm install @syukurilexs/nestjs-logUsage
Import LoggerModule:
imports: [LoggerModule.register()]This module is Global type, just import in module.app.js and can use it anywhere
Usage to write log to Elasticsearch and Console
To use Elasticsearch for logging you need to install Elasticsearch package
npm install @elastic/elasticsearchImport LoggerModule:
imports: [
LoggerModule.register({
elasticsearch: { node: 'http://localhost:9200', prefix: 'syukur' },
}),
],Options
- node: elastic search url
- prefix: index name (when use it with LoggerService it will append prefix log), and also today date, daily bucket)
Usage for Async method to write log to Elasticsearch and Console
To use Elasticsearch for logging you need to install Elasticsearch package
npm install @elastic/elasticsearchImport LoggerModule:
imports: [
LoggerModule.registerAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => {
return {
elasticsearch: { node: config.get('URL'), prefix: 'syukur' },
};
},
inject: [ConfigService],
}),
],Available Services
LoggerService
constructor(private readonly logger: LoggerService) {}
myMethod() {
this.logger.log('This is message');
this.logger.warn('This is warning');
this.logger.error('This is error','This is tracing' | {key: value});
}ReportService
constructor(private readonly report: ReportService) {}
myMethod() {
this.report.send({key: value, key2: value2});
}
Change Log
See Changelog for more information.
Contributing
Contributions welcome! See Contributing.
Author
Syukur LinkedIn
License
Licensed under the MIT License - see the LICENSE file for details.
