-
Notifications
You must be signed in to change notification settings - Fork 516
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
added CLI formatter function to bunyan module #102
base: master
Are you sure you want to change the base?
Conversation
What's the status of this? |
Anything happening with this? It'd be nice to have access to pretty printing via the module. This would make developing with bunyan a lot nicer. |
It'll probably need to be closed, since it's very big change, and it probably won't be merged cleanly. I ended up writing my own log formatter, you might want to do the same. |
Yeah, that's what I currently do. It just doesn't seem very DRY. |
What's the status of this?² |
Just chiming in here to say that I wish this were a thing! |
It should be just one small change as far as module interface is concerned.
I added a publicly available function
formatRecord
with a following interface:Implementation wasn't really that easy though. This function was in
bin/bunyan
and it needs to be available tolib/bunyan.js
as well. So it needs to be moved to some common place.Basically, I created a file
lib/common.js
(required by bothbin/bunyan
andlib/bunyan.js
) and moved all functions/variables that used in both places to that new file, removing all the duplicated code along the way.It directly fixes #84, and it makes #13 easy to do. With formatter function available to bunyan.js is should be trivial to add formatting when writing to stdout, though I didn't do it because it would be a big interface change.
All tests pass on node 0.10.x. Not sure if it means anything, because it's easy to slip bugs in such PR. So I intentionally split it to a lot of commits so you can see more easily where it's a cut-paste and where it's an actual change.
Note: formatRecord(rec, opts) messes with rec object (it's first argument), removing several keys, so it might be undesirable. Also, if rec isn't a valid record, function returns null (better to throw, but it'd be bad for performance).
That's how it works now: