nestjs-graylog
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

NestJS Graylog

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

Package Sidebar

Install

npm i nestjs-graylog

Weekly Downloads

176

Version

2.0.3

License

MIT

Unpacked Size

135 kB

Total Files

28

Last publish

Collaborators

  • appotter