-
-
Save jdmar3/4c2df3ffc8966c0ed666f5fa0b7fdefa to your computer and use it in GitHub Desktop.
Morgan JSON log format example
This file contains hidden or 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
'use strict'; | |
const morgan = require('morgan'); | |
module.exports = function jsonLog() { | |
return morgan(jsonFormat); | |
}; | |
function jsonFormat(tokens, req, res) { | |
return JSON.stringify({ | |
'remote-address': tokens['remote-addr'](req, res), | |
// 'remote-user': tokens['remote-user'](req, res), | |
'time': tokens['date'](req, res, 'iso'), | |
'method': tokens['method'](req, res), | |
'url': tokens['url'](req, res), | |
'http-version': tokens['http-version'](req, res), | |
'status-code': tokens['status'](req, res), | |
'content-length': tokens['res'](req, res, 'content-length'), | |
'referrer': tokens['referrer'](req, res), | |
'user-agent': tokens['user-agent'](req, res), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment