2.0.3 • Published 3 months ago

nestjs-graylog v2.0.3

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

Introduction

This is a simple wrapper of Graylog2 client library for NestJS.

Installation

npm install --save nestjs-graylog graylog2

Usage

Importing module

import { GraylogModule, GraylogService } from 'nestjs-graylog';

@Module({
  imports: [
    GraylogModule.register({
      serviers: [
        { host: '127.0.0.1', port: 12201 }
      ],
      hostname: 'hostname',// optional, default: os.hostname()
      facility: 'Node.js',// optional, default: Node.js
      bufferSize: 1400,// optional, default: 1400
    }),
  ],
  providers: [GraylogService],
  exports: [GraylogService],
})
export class GraylogProviderModule {}

Importing module Async

import { GraylogModule, GraylogService } from 'nestjs-graylog';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    GraylogModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        servers: [
          {
            host: configService.get('GRAYLOG_HOST'),
            port: +configService.get('GRAYLOG_PORT'),
          },
        ],
        facility: configService.get('GRAYLOG_FACILITY'),
      }),
    }),
  ],
  providers: [GraylogService],
  exports: [GraylogService],
})
export class GraylogProviderModule {}

Calling Method

import { GraylogService } from 'nestjs-graylog';

@Injectable()
export class YourService {
  constructor(private graylogService: GraylogService) {}

  async foo() {
    await this.graylogService.debug('test message', { foo: 'bar' });
  }

  // Also available in
  // this.graylogService.emergency('message')
  // this.graylogService.alert('message')
  // this.graylogService.critical('message')
  // this.graylogService.error('message')
  // this.graylogService.warning('message')
  // this.graylogService.notice('message')
  // this.graylogService.info('message')
}

Contributing

Contributions welcome!

Author

Phitsanu Chuamuangphan (GitHub)

LICENSE

MIT

2.0.3

3 months ago

2.0.2

3 months ago

2.0.1

3 months ago

2.0.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago