My rule of thumb is to log a bit more than i see fit, while keeping in mind that too few or too much logs == no logs.
We live in the era of Big Data. As such, a lot of developers log stuff carelessly, thinking “the data team will sort it out”. However, when you need to debug your application, there won’t be a data team around (or it would be too expensive to get them involved in every little bug you encounter).
Logging is a very important thing, especially in environments where you don’t have ready access to every single part of the running application (like Kubernetes). So log everything important, but think twice before deeming something as important.
On the other hand, debug logging is a handy tool in the hands of a developer, but it will most likely be turned off in production environments. Thus, important information should never enter the logs with a level equal to DEBUG. It should be dense enough, though, for the programmer to be able to follow code execution when looking at the logs.
So, for example, your production log should look like this:
INFO User X placed order Y
ERROR Could not verify payment from X2 for order Y2 after 7 days
…your debug log might look like this:
DEBUG Created order Y in orders.py:312
DEBUG Added item Z1 to order Y in orders.py:192
DEBUG Added item Z2 to order Y in orders.py:192
DEBUG Set order state to Ordered in orders.py:721
DEBUG Sent confirmation about order Y to user X in notifications.py:19
INFO User X placed order Y
DEBUG Fetching payment records for order Y2
ERROR Could not verify payment from X2 for order Y2 after 7 days