Hacker News new | ask | show | jobs
by jbail 4590 days ago
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...

1 comments

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.
I just pushed an updated Lumberjack using constructors. Take a peek: 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.

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