NestCloud - Logger
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
- Author - NestCloud
License
NestCloud is MIT licensed.