4.0.0 • Published 9 months ago

@syukurilexs/nestjs-log v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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.

4.0.0

9 months ago

3.0.0

1 year ago

2.0.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago