Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logging vs print
#2
After you set up logging in the places you want it, you can control it globally. If you have prints in different places and want to modify them, you have to edit every line to change their behavior.

You can leave debug logging in your code and keep it quiet most of the time, but turn it on when you're trying to find a problem. You can have all the logging go to a different file by changing one line.

If you have a 12 line script, it's easier to throw in a print statement to help debug something than set up logging (but lots of people would).
If you have 5000 lines of code in several modules, you don't want to be fiddling with print statements everywhere (and maybe forget to take some out because the code path isn't run very often and you didn't notice that you left some debugging lines active).

Standard logging formats give you discipline to put useful information in every time. I've been annoyed with production code that generated some logs, but had no indication of what module generated it, or timestamp. If they'd used standard log formatting, all that information would have been there.
syafiq14 and Gribouillis like this post
Reply


Messages In This Thread
logging vs print - by syafiq14 - Aug-28-2021, 04:26 AM
RE: logging vs print - by bowlofred - Aug-28-2021, 06:19 AM
RE: logging vs print - by snippsat - Aug-28-2021, 10:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  logging messages ahead of print messages vindo 6 3,452 Jun-18-2019, 02:45 PM
Last Post: vindo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020