Print Debugging vs Logging
People think print debugging is the same as logging, and it is not. Print lines are short-lived. You add them to chase one bug, then delete them. Logging stays in the code for good. It writes events with a time and a level, so people can read them long after the code ran.
Print Debugging
Adding lines that print values as the code runs. They show where it goes wrong.
Print debugging is finding a bug by adding lines that print values while the program runs. You put a print line at each step you are unsure about. When you run the code, the lines show each value and the order the steps ran in. The first value that looks wrong points to the bug. Once the bug is fixed, you take the extra lines out again.
Logging
Writing down what a program does, one timed line per event.
Logging is writing down events, one line at a time, as a program runs. Each line, called a log entry, has a time, a level and a message. It might say a user logged in, or a payment failed. The lines go to a file or to a tool that gathers logs from many servers. Logs are the place to look for the details of one event.
In one line
- Print Debugging
- Adding lines that print values as the code runs. They show where it goes wrong.
- Logging
- Writing down what a program does, one timed line per event.
These live in different corners of the glossary (Development and Infrastructure), which is exactly why they get confused.