mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:54:55 +00:00
refactor: update winston logger configuration for environment-based logging
This commit is contained in:
@ -1,18 +1,32 @@
|
|||||||
import { utilities as nestWinstonModuleUtilities } from 'nest-winston';
|
import { utilities as nestWinstonModuleUtilities } from 'nest-winston';
|
||||||
import * as winston from 'winston';
|
import * as winston from 'winston';
|
||||||
|
const environment = process.env.NODE_ENV || 'local';
|
||||||
|
|
||||||
export const winstonLoggerOptions: winston.LoggerOptions = {
|
export const winstonLoggerOptions: winston.LoggerOptions = {
|
||||||
level:
|
level:
|
||||||
process.env.AZURE_POSTGRESQL_DATABASE === 'development' ? 'debug' : 'error',
|
environment === 'local'
|
||||||
|
? 'debug'
|
||||||
|
: environment === 'development'
|
||||||
|
? 'warn'
|
||||||
|
: 'error',
|
||||||
transports: [
|
transports: [
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
|
level:
|
||||||
|
environment === 'local'
|
||||||
|
? 'debug'
|
||||||
|
: environment === 'development'
|
||||||
|
? 'warn'
|
||||||
|
: 'error',
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
nestWinstonModuleUtilities.format.nestLike('MyApp', {
|
nestWinstonModuleUtilities.format.nestLike('MyApp', {
|
||||||
prettyPrint: true,
|
prettyPrint: environment === 'local',
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
|
// Only create file logs if NOT local
|
||||||
|
...(environment !== 'local'
|
||||||
|
? [
|
||||||
new winston.transports.File({
|
new winston.transports.File({
|
||||||
filename: 'logs/error.log',
|
filename: 'logs/error.log',
|
||||||
level: 'error',
|
level: 'error',
|
||||||
@ -20,7 +34,10 @@ export const winstonLoggerOptions: winston.LoggerOptions = {
|
|||||||
}),
|
}),
|
||||||
new winston.transports.File({
|
new winston.transports.File({
|
||||||
filename: 'logs/combined.log',
|
filename: 'logs/combined.log',
|
||||||
|
level: 'info',
|
||||||
format: winston.format.json(),
|
format: winston.format.json(),
|
||||||
}),
|
}),
|
||||||
|
]
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user