Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Allow configuring formats per-exceptionHandler-transport within the same logger #2269

Open
NazCodeland opened this issue Jan 11, 2023 · 0 comments

Comments

@NazCodeland
Copy link

NazCodeland commented Jan 11, 2023

馃攷 Search Terms

logging to two files with two different formats

The problem

I am trying to log to two different files with two different formats for the same logging severity level. Very similar to issue #1401 however, instead of formats within a regular transport, it's about formats within exceptionHandler transports.

What version of Winston presents the issue?

v3.8.2

What version of Node are you using?

v19.1.0

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

This is what I have tried,

const fileNames = {
	exception: "./src/logger/logs/exceptions.json",
	exceptionReadable: "./src/logger/logs/exceptionReadable.log",
	}
	
const exceptionHandlers = [
	new winston.transports.File({ filename: fileNames.exception, format: json() }),
	new winston.transports.File({ filename: fileNames.exceptionReadable }),
];

const readableLogFormat = winston.format.printf(({ timestamp, level, message, stack }) => {
	return `${timestamp} ${level.toUpperCase()} ${stack || message}\n`;
});

const logger = winston.createLogger({
	level: process.env.LOG_LEVEL,
	format: combine(winston.format.errors({ stack: true }), timestamp(),  readableLogFormat),
	transports: transports,
	exceptionHandlers: exceptionHandlers,
});

Additional information

So, I have the readableLogFormat for all logs, and within the first "File" transport inside "exceptionHandlers", I've specified the json() format, but it doesn't work. In both files, I get the output of "readableLogFormat". This same exact thing works, specifying a format, for a regular "transports" but not when the format is inside a "exceptionHandlers" transport.

Anyone know why that is, or what am I doing incorrect?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant