hh-logger
A flexible and configurable logging library for NestJS, supporting Sentry and Datadog integrations.
Installation
Install the library using npm:
npm install hh-logger
Configuration
Sentry Integration
To use Sentry, provide the necessary DSN and other configuration options.
Datadog Integration
To use Datadog, provide the necessary API key and other configuration options.
Usage
AppModule Configuration
Import the HhLoggerModule
and configure it with your Sentry and Datadog credentials.
Example AppModule
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { HhLoggerModule } from 'hh-logger';
@Module({
imports: [
HhLoggerModule.forRoot({
sentry: {
dsn: 'your-sentry-dsn', // Replace with your Sentry DSN
environment: 'development',
debug: true,
},
datadog: {
apiKey: 'your-datadog-api-key', // Replace with your Datadog API key
hostname: 'your-datadog-hostname',
service: 'test-service',
env: 'development',
version: '1.0.0',
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Example AppController
Inject the HhLoggerService
and use it in your controllers to log messages.
import { Controller, Get } from '@nestjs/common';
import { HhLoggerService } from 'hh-logger';
@Controller()
export class AppController {
constructor(private readonly logger: HhLoggerService) {}
@Get()
getHello(): string {
this.logger.info('This is an info message');
this.logger.warn('This is a warning message');
this.logger.error('This is an error message');
return 'Hello World!';
}
}
License
This project is licensed under the MIT License.