Menu

1 / 2

Python logging: Stop Using print() in Your Automation Scripts

DEV Community·German Yamil·6 months ago
#zoGIpnpP
#pattern#python#beginners#logging#import
Reading 0:00
15s threshold

Python logging: Stop Using print() in Your Automation Scripts

You spent an hour debugging a cron job last night. The script ran fine manually, but in production it silently failed. You had no idea what happened because all your print() calls vanished into the void.

Here is the problem with print() :

Cron jobs discard stdout — your output goes nowhere unless you explicitly redirect it

No timestamps — you cannot tell when something happened

No severity levels — a warning and an error look identical

No filtering — you cannot say "show me only errors"

The fix is one import away: Python's built-in logging module.

Free: AI Publishing Checklist — 7 steps in Python · Full pipeline: germy5.gumroad.com/l/xhxkzz (pay what you want, min $9.99)

The Five Logging Levels

Before writing any code, understand the severity ladder:

Level Value When to use

DEBUG 10 Detailed diagnostic info (dev only)

INFO 20 Confirmation that things are working

WARNING 30 Something unexpected, but the script continues

ERROR 40 A…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.