const {message, stack} = new Error('NOT GOOD');
logger.error({message, stack}); // <--- calling winston logger
I am wondering if above code can be shorten it into single line, something like:
logger.error({message, stack} = new Error('NOT GOOD'));
This is how I format the winston log (in typescript):
// Creating file log message format
const logFormat = printf(({ level, message, timestamp, stack }) => {
return `${timestamp} ${level}: ${stack || message}`;
});
When I call:
logger.error(new Error('NOT GOOD'));
The output is as such:
2022-01-28 12:12:12 error: undefined
But if I:
const {message, stack} = new Error('NOT GOOD');
logger.error({message, stack}); // <--- calling winston logger
It work as intended. Display error message and stack.