

Show HN: I just open-sourced a small utility to make console.log better - jbail
https://github.com/jbail/lumberjack

======
ianbicking
console.stream() seems super fishy to me:
[https://github.com/jbail/lumberjack/blob/master/scripts/lumb...](https://github.com/jbail/lumberjack/blob/master/scripts/lumberjack.js#L30)

Here you are just changing a global default stream name, but it looks like you
have some kind of alternate console objects. E.g., as though I could do
"logger = console.stream('component'); logger.info(...);" in my code – but
that isn't how it works at all, it's just chaining and a method that means
something more like "console.setLogName('component')"

~~~
jbail
Thanks for the comment!

An insanely noisy console was bugging me this week, so I whipped up the
Lumberjack script in about an hour this Saturday while my daughter was
napping.

This is a super quick and dirty version #1 to prove that it can work and would
work as I imagined. I agree the "stream" name string stuff is wonky and could
be better. I've got some ideas I'll be playing with tomorrow. Basically taking
what I have and wrapping it up in a constructor, so console.stream('foo')
actually creates a 'foo' stream. You could then do (as I believe you suggest)
var foo = console.stream('foo'); foo.log(1); foo.warn(2); etc...

~~~
ianbicking
Yeah, a constructor would largely handle that. And if you use a closure/module
pattern, you could put a little "console =
window.console.stream('moduleName')" at the top of the module as a quick way
to customize the methods from that console. It might be nice to be able to
prefix messages with the relevant stream name too.

~~~
jbail
I just pushed an updated Lumberjack using constructors. Take a peek:
[https://github.com/jbail/lumberjack](https://github.com/jbail/lumberjack)

I need to update the Readme to show doing stuff like: var cat =
console.stream('cat'); cat.info('Meow'); cat.warn('Hiss!'); But, that should
work now. I really like being able to do that. Thanks for the suggestion.

Next steps...I'm not sure. I'm going to put this in place at my day job
tomorrow and see how it feels in production use. I was thinking it might be
cool to append/color the console with the stream name. Again, just to make the
console even easier to read if you do have a ton of streams getting logged
concurrently.

Prefixing messages could be cool too. Now with the Console constructor, you
sort of have a parent/child relationship. As long as the stream is a child of
the parent, it would work. Are you thinking something like this?

cat = console.stream('cat');

boobie = cat.stream('boobie'); karl = cat.stream('karl');

cat.log('boobie:meow'); cat.log('karl:hiss');

I'm not sure how that holds up when you want to log objects or arrays. What do
you envision? Let me know.

Thanks again for the comments. This is the first time I've open sourced
anything I've written. Getting feedback and hearing how other people might use
it and what they do and don't like about my code has been awesome. It's
already made this little utility way better than it started and its only been
out in the wild for 24 hours.

~~~
jbail
Replying to myself to say that I added color support. If you're using Firefox
or Chrome (which I believe are the only two browsers that support color in the
console at this time), then your stream names will be printed in color. This
really helps the console to pop and be more legible. You can view a demo here:
[http://jbail.github.io/lumberjack/demo.html](http://jbail.github.io/lumberjack/demo.html)

