Logging

Logging

Pyblish does not produce any output unless you explicitly tell it to.
If you enable the DEBUG level whilst developing plug-ins, Pyblish can tell you a few things about what is going on.
1
import logging
2
import pyblish.api
3
4
# Step 0, this doesn't produce any warnings..
5
pyblish.api.discover()
6
7
# Step 1, bring out the debug level messages
8
logging.getLogger("pyblish").setLevel(logging.DEBUG)
9
10
# Step 2, unless there already is a handler, one must be setup.
11
logging.basicConfig()
12
13
# Step 3, done
14
pyblish.api.discover()
15
# DEBUG:pyblish.plugin:Skipped: "collect_myplugin" (name 'pybddlish' is not defined)
Copied!
The handler can be customised to tailor the format and contents of the messages, like a timestamp and what not.
Read up on standard Python logging and corresponding handlers for more details.

Formatting

In the above example, messages weren't very pretty. You can control the formatting of messages like this.
1
# Fetch the logger Pyblish uses for all of its messages
2
log = logging.getLogger("pyblish")
3
4
# Do what `basicConfig` does, except explicitly
5
# and with control over where and how messages go
6
hnd = logging.StreamHandler()
7
fmt = logging.Formatter('%(message)s')
8
hnd.setFormatter(fmt)
9
log.addHandler(hnd)
10
11
pyblish.api.discover()
12
# Skipped: "collect_myplugin" (name 'pybddlish' is not defined)
Copied!
That %(message)s is one of the many variables available during formatting, see here for a full list.

Gotchas

    basicConfig will register a handler too, and it's possible to have many. See log.handlers for the ones currently registered, it's a plain Python list that you can clear to get rid of them.
    Autodesk Maya is special, it runs the equivalent of basicConfig under-the-hood at startup. Which means that you always see these messages whether you want to or not. You can remove handlers, and edit them despite this.
    Standalone Python doesn't have any handlers registered, and needs something like the above.
    See or start a conversation about this on the forums
Last modified 1yr ago
Copy link