@nestcfork/logger
TypeScript icon, indicating that this package has built-in type declarations

0.7.5 • Public • Published

NestCloud - Logger

NPM Version Package License NPM Downloads Travis Linux Coverage

Description

The logger module for nestcloud.

Installation

$ npm i --save @nestcfork/logger

Quick Start

import { NestFactory } from '@nestjs/core';
import { resolve } from 'path';
import { NestLogger } from '@nestcfork/logger';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { 
      logger: new NestLogger({
        filePath: resolve(__dirname, 'config.yaml'),
      }),
  });
}

Configurations

logger:
  level: info
  transports:
    - transport: console
      level: debug
      colorize: true
      datePattern: YYYY-MM-DD h:mm:ss
      label: user-service
    - transport: file
      name: info
      filename: info.log
      datePattern: YYYY-MM-DD h:mm:ss
      label: user-service
      # 100M
      maxSize: 104857600
      json: false
      maxFiles: 10
    - transport: dailyRotateFile
      filename: info.log
      datePattern: YYYY-MM-DD-HH
      zippedArchive: true
      maxSize: 20m
      maxFiles: 14d

Usage

Inject logger instance

import { Module } from '@nestjs/common';
import { LoggerModule } from '@nestcfork/logger';

@Module({
  imports: [
      LoggerModule.forRoot()
  ],
})
export class AppModule {}
import { Injectable, Logger } from '@nestjs/common';
import { InjectLogger } from '@nestcfork/logger';

@Injectable()
export class TestService {
  constructor(@InjectLogger() private readonly logger: Logger) {}

  log() {
      this.logger.log('The first log');
  }
}

Custom Typeorm Logger

import { Module, NEST_TYPEORM_LOGGER_PROVIDER } from '@nestjs/common';
import { TypeormLogger } from '@nestcfork/logger';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
      TypeOrmModule.forRootAsync({
          useFactory: (logger: TypeormLogger) => ({
              /* ... */
              logger,
          }),
          inject: [NEST_TYPEORM_LOGGER_PROVIDER],
      })
  ],
})
export class AppModule {}

Stay in touch

License

NestCloud is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i @nestcfork/logger

Weekly Downloads

1

Version

0.7.5

License

MIT

Unpacked Size

18.2 kB

Total Files

23

Last publish

Collaborators

  • kurbar