Skip to content
This repository has been archived by the owner. It is now read-only.
[Migrated to nestcloud repository]A logger module for nestcloud.
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.eslintrc.js
.gitignore
.npmignore
.prettierrc
README.md
index.d.ts
index.js
index.ts.js
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

Nest Logo

Description

A component of nestcloud. NestCloud is a nest framework micro-service solution.

中文文档

A logger module for nestcloud.

Installation

$ npm i --save @nestcloud/logger
$ npm i --save-dev @types/winston

Quick Start

import { NestFactory } from '@nestjs/core'
import { Injectable } from '@nestjs/core';
import { NestLogger, Logger } from '@nestcloud/logger';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { 
      logger: new NestLogger({path: __dirname, filename: 'logger.yml'})
  });
}

Config logger.yml

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, Logger } from '@nestcloud/logger';

@Module({
  imports: [
      LoggerModule.register()
  ],
})
export class ApplicationModule {}
import { Injectable } from '@nestjs/common';
import { InjectLogger, Logger } from '@nestcloud/logger';
import { LoggerInstance } from 'winston';

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

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

Custom Typeorm Logger

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

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

Stay in touch

License

NestCloud is MIT licensed.

You can’t perform that action at this time.