使用winston嵌套日志记录不创建文件



我正在尝试在我的嵌套应用程序中实现lgger,它显示控制台,但不创建文件。。app.module.ts

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AdminuserModule } from './adminuser/adminuser.module';
import {
utilities as nestWinstonModuleUtilities,
WinstonModule,
} from 'nest-winston';
import * as winston from 'winston';

@Module({
imports: [
WinstonModule.forRoot({
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.timestamp(),
nestWinstonModuleUtilities.format.nestLike(),
),
}),
],
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }

app.controller.ts

import { Controller, Get, Inject } from '@nestjs/common';
import { AppService } from './app.service';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston';
@Controller()
export class AppController {
constructor(private readonly appService: AppService,@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {}
@Get()
getHello(): string {

this.logger.info('Calling getHello()', { controller: AppController.name });
return this.appService.getHello();
}
}

它是登录控制台,但我也需要登录到文件中。。我该怎么做?

您可以向AppModule添加更多传输,例如:

transports: [
new transports.File({ filename: "error.log", level: "error" }),
new transports.File({ filename: "combined.log" }),
new transports.Console(),
],

最新更新