Using Python Logging to Figure Out What You Did Wrong
As a warning to everyone, I am not a developer. I am a network engineer who is trying to do some automation stuff. Some of what I’m doing sounds logical to me, but I would not trust my own opinions for production work. I’m sure you can find a Slack channel or Mastodon instance with people who can tell you how to do things properly.
I use too many print statements to figure out what’s going on. Get an object and print it to screen to make sure it’s right. Do a calculation and print the result. There are so many print statements in my code that I had to start using a debug variable to tell it when to print stuff. I even use that technique in my functions.
# Don't do stuff like this
def myFunc(string_to_return, debug=False):
if debug:
print(f"Returning \"{string_to_return}\"")
return string_to_return
local_debug = True
string_to_send = "Aaron wastes a lot of time with print statements."
if local_debug:
print(f"I'm sending \"{string_to_send}\"")
myString = myFunc(string_to_send, debug=True)
print(myString)
It’s painful to look at this code. I need a better solution, and I found Python’s logging module.
Very simply, you associate your messages with one of five logging levels (debug, info, warning, error, Continue reading

s Law divide, at least for some applications.

