日志管理
原创...小于 1 分钟
安装
npm install --save nest-winston winston winston-daily-rotate-file
配置
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { WinstonModule } from 'nest-winston';
import * as winston from 'winston';
import * as DailyRotateFile from "winston-daily-rotate-file"
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: WinstonModule.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
),
transports: [
new DailyRotateFile({
filename: 'src/logs/info-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '15d',
level: 'info',
}),
new DailyRotateFile({
filename: 'src/logs/error-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '15d',
level: 'error',
})
],
})
});
await app.listen(3000);
}
bootstrap();
Powered by Waline v2.15.7