Created
February 12, 2018 12:48
-
-
Save Kmaschta/e3d0937334ac9fcccbbaf5c20b63627a to your computer and use it in GitHub Desktop.
Express-Winston Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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