I cannot be the first developing on Windows 10 and wanting the log-files in dev mode on the localhost and pump/pipe it into /var/logs/myservice
folder if it is in integration or production.
How can one replace the window path with a linux path according to environment variables?
In this case I use winston and nestjs.
import { Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { AppController } from './app.controller';
import { AppGateway } from './app.gateway';
import { AppService } from './app.service';
import { WinstonModule } from 'nest-winston';
import * as winston from 'winston';
@Module({
imports: [
WinstonModule.forRoot({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'trading-signal-listener' },
transports: [
//
// - Write all logs with level `error` and below to `error.log`
// - Write all logs with level `info` and below to `combined.log`
//
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),
],
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Any help appreciated.
CodePudding user response:
I'm not quite sure what's your problem, can't you just use @nestjs/config
as described here https://docs.nestjs.com/techniques/configuration and based on environment variables pass a specific path to your WinstonModule?