I am trying to decide on what logging module to try out for my next project. I'd love the dev community's input on:
A) What logging lib you use
B) Whether you structure your logs (and how)
C) Where you store your logs or any other logging infra you have
I have been using Winston, but I would like something that supports structured logging out of the box. The general ecosystem on NPM seems to be pretty split, and some options seem to be popular but un-maintained.
Top comments (44)
There is only one thing I use:
And I reset (and remove) my logs after the code has been proven stable. :-) Generally, logging should remain a debugging feature. The users won't need it.
The problem with using console directly is that there are browsers out there (probably only real old ones though) that simply crash your code right away because console is undefined when the developer tool is not opened. Also some interpreters, such as Nashorn which comes with Java, simply do not have a console defined.
If you want to avert that risk and still only use the console for logging, you should write code similar to this:
However, this means testing
logbefore each call tolog.info... You could maybe do this to prevent that test:However, you would also have to make dummies for warn(), error() etc... In the end you would be building a shim... Which is exactly how ulog started. I understand your desire to keep logging simple and not use any external libs for it... But really the state of JS today is that 'simple' logging either is broken (crashes on some systems), is not actually 'simple' (see code examples above), or does use a library. I built ulog from the desire to make it as close to using no lib at all, while actually solving those problems. If you never use any logging lib, ulog was built with you in mind! Please try it and let me know.
I also do this. But Iβm curious about other answers in the thread.
Since I'm just starting learning node I came to this post with some hesitation since I really didn't know if
console.log()was an acceptable answer. Thanks for the clarification. hahahaBefore I proceed I must warn you I am the author of the logging library I am using, so there is a tiny possibility that I might be biased. Very tiny :)
ulog - The microscopically small universal logger
Basically ulog is debug meets loglevel meets the console. It works in Node JS and all major browsers (even old ones!)
Why I built it
It started out because using console directly is basically VERBOTEN. Because some browsers simply don't support it and will crash your code. Also you need to remove these statements afterwards etc. Making logging difficult and error prone. So it started as a tiny shim that just makes sure that your code never crashes or fails whether console is available or not.
I then decided I wanted log level support so I added that. And then I discovered debug, which is GREAT, and I decided to copy those features I loved about that.
Why I think it is one of the best loggers
Example usage
Yields (on browsers)
If you want to try it
Now is the perfect time as I am trying to perfect v2 currently. So if you want to try this, please install the beta and let me know:
Or you can use v1, but that version is more limited in features: