It would be nice to change the logging format of Flashheart.
For data/log visualisers that leverage JSON logs like Kibana, having the upstream access log as a single message becomes hard to parse, i.e.
GET http://echo.jsontest.com/hello/world 200 10 ms
Libraries like Morgan allow for custom format functions, e.g.
morgan((tokens, req, res) => tokens)
Which would return the JSON object of all of the tokens that Morgan monitors.
Since Flashheart allows you to inject your own logger, it makes sense (to me at least) to be able to define your own formatter to return the right thing for the logger to consume.
This could also give users access to more information that's on the request and response options, I would like to be able to define something like
const format = (req, res) => ({ short: `${req.method} - ${res.statusCode}`, time: res.elapsedTime })
createClient({ format, logger })
And this could easily be done here with something like;
Client.prototype._log = function (res) {
var debugMessage = util.format(res.request.method, res.request.href, res.statusCode, res.elapsedTime, 'ms');
debug(debugMessage);
if (this.logger) {
var logMessage = this.format
? this.format(res,request, res)
: debugMessage
this.logger.info(logMessage);
}
};
Assuming that you still want the debug message to be string only.
What do you guys think?