reporter - human-formatter enhancement request
nevf opened this issue · comments
The Bunyan reporter output for arrays is currently one long string. It would be much, much better if it was nicely formatted.
So instead of:
items: [{ id: "6356af00-ca8c-423e-9a74-0fa3ca600e3d", title: "Gym workout", completed: "false" }, { id: "6d6e49b0-ba36-4a78-85f7-0f4023551d56", title: "Doodle", completed: "false" }, { 0: { id: "15e65afb-409a-4e7e-bbd7-e5d1b2d3db95", title: "Sauna", completed: true }, id: "15e65afb-409a-4e7e-bbd7-e5d1b2d3db95", title: "Sauna", completed: "false" }, { id: "10c9cce8-048b-4d38-b5cd-7ddb96c1a0cd", title: "Play the Old on the morrow", completed: "true" }, { id: "bf71e298-40e3-4466-bf66-20de71182724", title: "Swim", completed: "false" }, {
id: "a492941f-84c8-4cc9-88a0-d7cef9cc2451", title: "Red", completed: "false" }, { id: "30d0db7c-383e-4f76-9cb8-5b99bd7a7ded", title: "123", completed: "false" }]
you would see:
items: [
{
id: "6356af00-ca8c-423e-9a74-0fa3ca600e3d",
title: "Gym workout",
completed: "false"
},
{
id: "6d6e49b0-ba36-4a78-85f7-0f4023551d56",
title: "Doodle",
completed: "false"
},
{
0: {
id: "15e65afb-409a-4e7e-bbd7-e5d1b2d3db95",
title: "Sauna",
completed: true
},
id: "15e65afb-409a-4e7e-bbd7-e5d1b2d3db95",
title: "Sauna",
completed: "false"
},
I've added https://www.npmjs.com/package/jsome and use that to format json before passing it to reporter and that works nicely. Maybe jsome could be used in human-formatter!
You write Bunyan output directly to the console?
It has spaces for a purpose — to be fast. Bunyan output is an internal format to be used in some tool. Not to read it. There is better human
log formatter to read it.
As I know Bunyan way is to use some processor to convert output ./server.js | npx some-bunyan-tool
. For example, check out https://github.com/thlorenz/bunyan-format
These tools is better also because they add syntax highlight.
I wrote this simple function to use the Logux reporter + human-formatter code.
/** Display spec'd info using the Logux specified logger to the console.
*/
function debug_logger( action, meta, msg ){
app.reporter.logger.info( { action: action, meta: jsome.getColoredString( meta ) }, msg || '' )
}
I merge meta
with any other objects I want to log. jsome formats the output nicely as shown in my first example. human-formatter does a good job with objects, but not arrays, hence my suggestion.
I've never used Bunyan before so my knowledge of it is extremely limited so far).
Closing since there is a lot of Bunyan tools to make output prettier.