Skip to content

Instantly share code, notes, and snippets.

@Kmaschta
Created February 12, 2018 12:48
Show Gist options
  • Save Kmaschta/e3d0937334ac9fcccbbaf5c20b63627a to your computer and use it in GitHub Desktop.
Save Kmaschta/e3d0937334ac9fcccbbaf5c20b63627a to your computer and use it in GitHub Desktop.
Express-Winston Benchmark
const express = require('express');
const winston = require('winston');
const expressWinston = require('./express-winston');
const app = express();
const consoleFormatter = ({ level, meta: { req, res, responseTime, stack } }) => {
let msg = `${winston.config.colorize(level, level)} HTTP ${req.method} ${req.url}`;
if (res) {
msg += ` ${res.statusCode}`;
}
if (responseTime) {
msg += ` (${responseTime}ms)`;
}
if (stack) {
msg += `\n ${stack.join('\n')}`;
}
return msg;
};
app.use(expressWinston.logger({
colorize: true,
expressFormat: true,
meta: true,
transports: [
new winston.transports.Console({
colorize: true,
formatter: consoleFormatter,
})
],
}));
app.listen(3000, () => {
console.log('Listing on port 3000');
});
{
"dependencies": {
"express": "4.16.2",
"winston": "2.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment