-
Notifications
You must be signed in to change notification settings - Fork 458
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
Any suggestions on good logging practice? #119
Comments
Have you seen #104? On topic, this should work. haven't tested. // Based on https://www.npmjs.com/package/morgan#vanilla-http-server
const { send } = require('micro')
const morgan = require('morgan')
const logger = morgan('combined')
module.exports = async function (req, res) {
logger(req, res, function (err) {
if (err) {
return send(res, 500, 'Error')
}
send(res, 200, 'OK!')
})
})
// Using pify to turn logger into a Promise.
const { send } = require('micro')
const pify = require('pify')
const morgan = require('morgan')
const logger = pify(morgan('combined'))
module.exports = async function (req, res) {
await logger(req, res)
return 'OK!'
}) |
I did see #104 but I figured it would be useful to be able to customise the log output, especially as I have one project that needs to log JSON to stdout to be picked up by fluentd. Thanks for the tips. |
👍 |
More of a question than a bug, I was wondering how you have handled logging with
micro
?I'd like to get some reasonable logging (e.g. response time, status, request content length etc.) out of my microservice. I've spent 5 mins playing around trying to get
morgan
to play withmicro
but it follows the middleware ideology whichmicro
doesn't.Any tips would be great! Thanks for open sourcing this 👍
The text was updated successfully, but these errors were encountered: