-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
winston.rejections returns undefined #1955
Comments
Hello @Suren55 I think there is a mistake in the docs: this should be the Maybe you could do something like: const { createLogger, transports, format } = require('winston');
const logger = createLogger({
format: format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }),
format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
),
transports: [
new transports.Console(),
]
});
logger.rejections.handle(
new transports.File({ filename: 'rejections.log' })
);
logger.info("Start ...");
const myPromise = new Promise((resolve, reject) => {
reject('Ouch');
});
myPromise.then(() => {
console.log('Hello World');
}); |
Hi @andreasvogt89. Thank you for the reply, however I am not sure that it's a mistake in the docs, because the same logic exists for Also, thank you for the piece of code you provided, but I did not want to create a custom logger, I wanted to use the default one for now. |
Yes you are right, it does not work for the default logger. The problem is that If I try to use the alternativ way like below, it caught the const winston = require('winston');
winston.add(new winston.transports.File({
filename: 'rejections.log',
handleRejections: true
}));
winston.info('Starting. . . ');
const myPromise = new Promise((resolve, reject) => {
reject('Ouch');
});
myPromise.then(() => {
console.log('Hello World');
}); I think best way to solve would be to add /**
* Define getters / setters for appropriate properties of the default logger
* which need to be exposed by winston.
* @type {Logger}
*/
['exitOnError', 'rejections'].forEach(prop => {
Object.defineProperty(winston, prop, {
get() {
return defaultLogger[prop];
},
set(val) {
defaultLogger[prop] = val;
}
});
}); |
Please tell us about your environment:
winston
version?winston@3
node -v
outputs: 14.16.1What is the problem?
winston.rejections
isundefined
when trying to call:winston.rejections.handle( new winston.transports.File({ filename: 'rejections.log' }) );
What do you expect to happen instead?
I expect to be able to make the above mentioned call and log the error.
The text was updated successfully, but these errors were encountered: