-
Notifications
You must be signed in to change notification settings - Fork 186
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
Does express-winston make morgan redundant? #167
Comments
I discovered this package yesterday and I am currently using morgan. I have just removed the morgan dependency because @stoberov's question back in 2018 is 100% legit and was the first thing I was wondering after reading through the docs for express-winston as well. I read through the entire discussion that @lonix1 linked but the link is regarding a call for maintainers. I don't see how it's relevant at all unless he was suggesting we drop this package in favor of morgan due to waning interest. Anyway, this question doesn't seem to be answered and nobody has touched it for 4 years so I am hoping to revive it. I am looking for direction as to whether removing morgan was a mistake. Perhaps one of the active maintainers can straighten this out? |
Hi @fated-x, For what it's worth, my thoughts 4 years later are:
Frankly, my personal recommendation would be to skip both, just install // logger.js
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, colorize, printf } = format;
const env = process.env.NODE_ENV || 'development';
const consoleTransport = new transports.Console({
format: combine(
colorize(),
timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
)
});
const logger = createLogger({
level: env === 'production' ? 'info' : 'debug',
transports: [consoleTransport], // more transports as desired
handleExceptions: true
});
module.exports = logger;
// middlewares.js
const requestLogger = (req, res, next) => {
const { url, method, query, body } = req;
const request = JSON.stringify({
url,
method,
query,
body // some parameters may be worth masking/skipping, e.g. passwords
});
logger.info(request);
next();
};
module.exports = {
requestLogger,
// more middlewares if needed
}
// index.js
/** Express code here */
server.use(requestLogger); The main argument I can make for using just Just my $0.02 :) |
Hey,
Thanks for such an awesome middleware! There's one thing that confuses me though - could you please clarify for me?
"Traditionally", we would use Morgan for logging HTTP requests and then Winston for all other logging needs. Am I right to assume that with express-winston we don't really need morgan any more, because express-winston does the same job and is capable of much more, too?
The text was updated successfully, but these errors were encountered: