0.0.7 • Published 1 year ago

sobbey-micro-logger v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Description

Nest utility module for multi level logging. Includes logging in Nest Console, Logs Files and Grafana Loki

Installation

$ npm install sobbey-micro-logger

Logger Config

import { ConfigModule, ConfigService } from '@nestjs/config';
import { IMicroLoggerModuleAsyncOptions } from 'sobbey-micro-logger';

export const getLoggerConfig = (): IMicroLoggerModuleAsyncOptions => ({
  inject: [ConfigService],
  imports: [ConfigModule],
  useFactory: (configService: ConfigService) => ({
    APP_NAME: configService.get('APP_NAME') ?? 'API',
    LOG_PATH: `${process.cwd()}/publisher/${configService.get('APP_NAME')}`,
    LOKI_HOST: configService.get<string>('LOKI_URL'),
  }),
});

Declaring MicroLogger Module

@Module({
  imports: [
    ConfigModule.forRoot({ envFilePath: '.env', isGlobal: true }),
    MicroLogModule.forRootAsync(getLoggerConfig()),
  ],
  exports: [MicroLogModule],
})
export class SetupConfigModule {}

Support

sobbey-micro-logger is an open source project. It can grow thanks to the sponsors and support by the amazing backers.