I've recently started work on a new application and I instantly jumped into setting up Winston to enable the glorious fire hosing of log messages to console as well as syslog. Whilst I was happily working away through my code, setting various log calls some at error level, some debug and a few info messages thrown in it hit me...
These log messages are of benefit to ME, but are they of any use to another developer or infact any human that isn't me?!
I instantly dived to google thinking "Someone would have written this down.."
However, the opinions out there are very split. Since Dev.to is a nice community with people who share their knowledge I'd love to get an insight into the mechanics you run through deciding:
- When should I be logging information?
- What information should a log message always contain and what is optional?
- How do you decide what level this log should be set to there's many info, trace, debug, error, warn and even "verbose".
I have to say, sometimes I openly throw in log messages purely for my own benefit, simply because sometimes I don't believe my program is even working if I don't see the stack of lines running through my terminal assuring me that everything is well in the world.
Opinions please :)
I find generalised logging useless. Unless you have your specific tasks, you want to solve with logging, it will just create a lot of digital noise and clutter up your code. So, define your tasks, find the best tool to solve it (maybe it will be logging), implement the solution.