Knowledgebase

Using Logging Instead of Printing Print

  • python, errors, guide, howto, solution, zillionkinghost, hosting, support
  • 0

For anything beyond a quick check.

WHY LOGGING RATHER THAN PRINTING

Levels, so you can control verbosity Destinations, so output can go to a file Formatting, including timestamps It can be left in place

THAT LAST POINT

Print statements get removed and re-added constantly.

Logging stays, and is silenced by configuration.

WHAT THE LEVELS ARE FOR

Detailed diagnostic information Routine progress Something unexpected but handled An error A serious failure

WHAT TO SET IN DEVELOPMENT

A verbose level.

WHAT TO SET IN PRODUCTION

A level recording what matters without excessive volume.

WHAT TO INCLUDE IN A MESSAGE

What happened, with the relevant values.

A message saying only "error" is useless.

WHAT NOT TO LOG

Credentials Full personal data Every iteration of a loop

WHERE TO CONFIGURE IT

Once, at application startup.

WHAT TO AVOID

Configuring logging inside library code Several competing configurations


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot