I always had trouble finding those console logs in the console that I add for debugging. So I made this pretty log formatter (for Winston) that separates each statement via a blank line, colorizes it, pretty-prints the metadata and includes information where in the source the log statement was used. Feedback welcome! :)
Very interesting. Coming from the java world i'm very perplex at logging with nodejs and still haven't found a solution that makes me feel comfortable: you have to throw errors and analyze the stack to get the calling method or another thing that can happen with winston is that chronological order is not guaranteed
Yeah, NodeJS is indeed lacking some proper introspection functionality :(
What I'm doing to get the call stack really is nothing but an ugly hack. And users of this logger even have to do the annoying `log = init(log)` dance to make the hack work. Because if I had put the hack inside the formatter directly I would not have been able to get the actual calling location from the stack trace, as NodeJS is limiting the stack trace length to 10 entries by default, which in this case would be too short.
So the strong arguments for JS really aren't its language design and features but rather the fact it can be used universally in backend, frontend and mobile (i.e. allows for code sharing, less context switching during development if you're "fullstack"). Wish there were more languages that would easily support that :)
3 comments
[ 3.6 ms ] story [ 14.4 ms ] threadWhat I'm doing to get the call stack really is nothing but an ugly hack. And users of this logger even have to do the annoying `log = init(log)` dance to make the hack work. Because if I had put the hack inside the formatter directly I would not have been able to get the actual calling location from the stack trace, as NodeJS is limiting the stack trace length to 10 entries by default, which in this case would be too short.
So the strong arguments for JS really aren't its language design and features but rather the fact it can be used universally in backend, frontend and mobile (i.e. allows for code sharing, less context switching during development if you're "fullstack"). Wish there were more languages that would easily support that :)