@syukurilexs/nestjs-log
v4.0.0
Published
NestJS syukurilexs logger
Downloads
33
Readme
Installation
npm install @syukurilexs/nestjs-log
Usage
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/elasticsearch
Import 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),
- date (default to YYYYMMDD, "." sperated)
- log
- report
- date format
- DATE_FORMAT.YYYYMMDD
- DATE_FORMAT.YYYYMM
- DATE_FORMAT.YYYY
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/elasticsearch
Import 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});
}
// Add specific prefix per method call
myMethod2() {
this.report.send({key: value, key2: value2},'prefix');
}
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.