1.0.2 • Published 3 years ago

report-to-rollbar v1.0.2

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

Installation

NestJS Rollbar package allows you to extend standard Logger to send errors directly to Rollbar. Usage if quite simple. Get Rollbar Token from your project page and install nestjs-rollbar package:

npm i report-to-rollbar nestjs-rollbar

Then register module in your root app.module

import { LoggerModule } from 'nestjs-rollbar';
import { ReportRollbarModule } from 'report-to-rollbar'

@Module({
	imports: [
		// ...
		LoggerModule.forRoot({
      accessToken: process.env.ROLLBAR_ACCESS_TOKEN,
      environment: process.env.ROLLBAR_ENVIRONMENT
    }),
    ReportRollbarModule,
	],
})
export class AppModule {}

To use RollbarLogger in any service or controller just inject it in constructor:

import {
  ReportRollbarService,
  Type
} from 'src/report-rollbar/report-rollbar.service'

constructor(
		private readonly reportRollbarService: ReportRollbarService
	) {}

To log an error to Rollbar just call reportToRollbar() method:

try {
	throw new Error('Test error');
} catch (error) {
	this.rollbarLogger.reportToRollbar(
        `myMethod`,
        e,
        Type.error,
        null,
        e.data,
        e.config,
        null
      )
}

First parameter is the name of your method to show in logs, second an error object third the Type of the error, fourth the payload, fifth the variables, sixth the request sent, and seventh the environment chosen.

Change Log

See Changelog for more information.

Contributing

Contributions welcome! See Contributing.

Author

Keybe - Mauro Cominotti

License

Licensed under the MIT License - see the LICENSE file for details.

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago