Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const uppercaseTransformer = (info: TransformableInfo): TransformableInfo => {
info.level = info.level.toUpperCase()
return info
}
const colors = {
debug: 'dim',
info: 'cyan',
warn: 'yellow',
error: 'red',
}
return _createLogger({
level: LOG_LEVEL,
// Need to upper case level before colorization or we destroy ANSI codes
format: format.combine({ transform: uppercaseTransformer }, format.colorize({ level: true, colors }), {
transform: formatTransformer,
}),
defaultMeta: { service },
transports: [new transports.Console({})],
})
}
private setupLogger() {
const level = this.verbose ? 'debug' : 'info';
const transports = this.logToFile
? [new winston.transports.File({ filename: LOG_FILE })]
: [new winston.transports.Console()];
this.logger = winston.createLogger({
level,
format: format.combine(
format.colorize(),
format.timestamp(),
format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
),
transports
});
}
}
useFactory: () => {
const LOG_LEVEL = process.env.LOG_LEVEL;
let output = format.json();
if (process.env.NODE_ENV === 'develop') {
output = format.combine(
format.colorize(),
format.printf((nfo: TransformableInfo) => {
let formattedOutput = `${nfo.timestamp} ${nfo.level}: ${nfo.message}`;
if (nfo.metadata && Object.keys(nfo.metadata).length !== 0) {
formattedOutput += `\n${JSON.stringify(nfo.metadata, null, 4)}`;
}
return formattedOutput;
}),
);
}
return createLogger({
level: LOG_LEVEL,
format: format.combine(
format.metadata(),
format.timestamp(),
output,