logging vs print

It’s extremely useful to add print statements to our code, so we can track down the progress and variables as the code run.
But it get’s dirty and hard to read when lots of print lines run from multiple scripts.

That’s where python built-in logging module comes to the rescue!
in a nut shell, this module is thread safe, supports logging to stdout/shell, files, emails, http and over network.
Check out logging documentation for more: http://docs.python.org/release/2.7/library/logging.html

Where it’s come really useful is when you need to communicate an error or a message so it won’t get lost!
In some cases you would want to log directly into an email or into s log-file to keep track.
What ever the case is, logging can do it with it’s built-in handlers.

I started cgLogger, an OpenSource wrapper over the build-in logging module, that supports logging in Nuke and Maya using their native commands. This takes advantage of logging messages in a way that will get the artists attention ( or at less more likely to do so ). In many cases it’s very to communicate warning/errors out to the end-user. There for the cgLogger will raise a messageBox for level ERROR and CRITICAL to make sure we have end-user attention.

Code in GitHub:https://github.com/asisudai/cg-logging
This code was inspired by Alex Segal. Thank you Alex.

One thought on “logging vs print

  1. One of the biggest advantages of proper logging is that you can categorize messages and turn them on or off depending on what you need. For example, it might be useful to turn on debugging level messages for a certain part of the project, but tone it down for other parts, so as not to be taken over by information overload and to easily concentrate on the task for which you need logging.

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha! *