You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import winston from 'winston';
// Define the levels that can be used for logging
const levels = {
error: 0,
warn: 1,
info: 2,
http: 3,
debug: 4,
};
// // In debug mode show all logs, otherwise show only warn and error
// const level = () => {
// const env = process.env.NODE_ENV || 'development'
// const isDevelopment = env === 'development'
// return 'all'
// }
// Define the color each level will be logged with
const colors = {
error: 'red',
warn: 'yellow',
info: 'green',
http: 'magenta',
debug: 'white',
};
// Tell winston to use the colors we defined
winston.addColors(colors);
// Define the format in which we want to log
const format = winston.format.combine(
winston.format.timestamp(),
winston.format.colorize(),
winston.format.json()
);
// Tell winston to log to console and to a file
const transports = [
new winston.transports.Console(),
new winston.transports.File({
filename: './logs/auth.log',
handleExceptions: true,
maxsize: 5242880,
maxFiles: 5,
format: format
})
];
const logger = winston.createLogger({
level: 'debug',
levels,
format,
transports
});
export default logger;
I then passed it to the forRoot method like so:
import logger from './lib/logger.js';
import { Module } from '@nestjs/common';
import { WinstonModule } from 'nest-winston';
import { AppController } from './app.controller.js';
import { AppService } from './app.service.js';
import { RabbitMqModule } from './rabbit-mq/rabbit-mq.module.js';
@Module({
imports: [RabbitMqModule,
WinstonModule.forRoot({
instance: logger
})],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
It doesn't work, the transports don't get registered...
I think the problem is within the method createWinstonProviders, it always uses the factory of () => createLogger(...) instead of returning the instance if it was defined...
The text was updated successfully, but these errors were encountered:
I have the following logger.ts file:
I then passed it to the forRoot method like so:
It doesn't work, the transports don't get registered...
I think the problem is within the method createWinstonProviders, it always uses the factory of () => createLogger(...) instead of returning the instance if it was defined...
The text was updated successfully, but these errors were encountered: