0.2.16 • Published 6 months ago

@bluepic/logdna-nestjs v0.2.16

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

npm version ISC license

This is a fork of @ntegral/nestjs-sentry

Table Of Contents

About

@bluepic/logdna-nestjs implements a module, LogDNAModule, which when imported into your nestjs project provides a LogDNA client to any class that injects it. This lets LogDNA be worked into your dependency injection workflow without having to do any extra work outside of the initial setup.

Installation

npm install --save @bluepic/logdna-nestjs @logdna/logger

Getting Started

The simplest way to use @bluepic/logdna-nestjs is to use LogDNAModule.forRootAsync

import { Module } from '@nestjs-common';
import { LogDNAModule } from '@bluepic/logdna-nestjs';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    LogDNAModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        ingestionKey: configService.get('LOGDNA_INGESTION_KEY'),
        logDNAOptions: {
          app: 'App Name',
          env: process.env.NODE_ENV,
          defaultLevel: 'info',
          hostname: 'Hostname',
        },
      }),
      inject: [ConfigService],
    });
  ],
})
export class AppModule {}

You can then inject the LogDNA client into any of your injectables by using a custom decorator

import { Injectable } from '@nestjs/common';
import { LogDNAService, InjectLogDNA } from '@bluepic/logdna-nestjs';

@Injectable()
export class AppService {
  constructor(@InjectLogDNA() private readonly logger: LogDNAService) {}
  testLogger() {
    this.logger.log('TEST');
  }
}

You can instruct Nest to use the LogDNAService as the default logger:

import { LogDNAService } from '@bluepic/logdna-nestjs';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { logger: false });

  app.useLogger(LogDNAService.LogDNAServiceInstance());

  await app.listen(3000);
}
bootstrap();

Middleware

You can use the LogDNAhttpLogger Middleware to automatically log all incoming requests/outgoing responses

import { LogDNAhttpLogger } from '@bluepic/logdna-nestjs';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.use(LogDNAhttpLogger({
    filter: (req, res) => res.statusCode == 500
  }))

  await app.listen(3000);
}
bootstrap();

Exception Filter

You can use the LogDNAhttpExceptionLogger to automatically log exceptions

import { LogDNAhttpExceptionLogger } from '@bluepic/logdna-nestjs';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalFilters(new LogDNAhttpExceptionLogger({
    generateReference: true
  }));

  await app.listen(3000);
}
bootstrap();

License

Distributed under the ISC License. See LICENSE for more information.

Acknowledgements

0.2.16

6 months ago

0.2.15

6 months ago

0.2.14

7 months ago

0.2.13

7 months ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago