Skip to content
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

fix: log in/out bodies for requests that have body parsed with json() #35

Merged
merged 1 commit into from Sep 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/log.js
Expand Up @@ -92,6 +92,10 @@ const initLog = (req, res) => {
const start = new Date()
const requestIndex = ++requestCounter

console.log(chalk.grey(`\n${'—'.repeat(process.stdout.columns)}\n`))

const reqBodyReady = logRequest({ req, start, requestIndex })

const end = res.end

res.end = (chunk, encoding, callback) => {
Expand All @@ -101,9 +105,7 @@ const initLog = (req, res) => {
const requestTime =
delta < 10000 ? `${delta}ms` : `${Math.round(delta / 1000)}s`

console.log(chalk.grey(`\n${'—'.repeat(process.stdout.columns)}\n`))

logRequest({ req, start, requestIndex }).then(() => {
reqBodyReady.then(() =>
logResponse({
res,
start,
Expand All @@ -112,7 +114,7 @@ const initLog = (req, res) => {
requestIndex,
chunk
})
})
)

return res.end(chunk, encoding, callback)
}
Expand Down