← All ideas
  • Published 1 Nov 2016

Python Logging Defaults & Display for blender

During Dr. Sybren's blenderconf 2016 talk, ( stuvel.eu/blog/213/blender-conference-2016 ), there was quite a discussion about logging.

He mentioned a bunch of custom settings he uses for logging in blender, including the logging format:

'%(asctime)-15s %(levelname)8s %(name)s %(message)s'

for instance. To get this kind of logging requires quite a bit of (trivial) fiddling around with your environment, and won't be added by default, as it no longer matches vanilla python.

There are many benefits to using the python logging module, as listed in his talk.

The big problems why logging is not used by more developers are (as I see is) as follows:

  • Require too much fiddling around with your environment
  • Don't give enough obvious benefit in the simple case
  • Aren't used in example code in the manual

Another problem which could be addressed simultaneously is that for many users it's non-obvious to get access to the stdout where logging usually occurs (especially on Windows).

I propose the following (not all my original ideas, but following discussion in Sybren's talk):

  • A bpy.getLogger (or bpy.utils.getLogger ) that returns a logging object with good obviously beneficial defaults. (the above mentioned format string, for instance).
  • This logger's default behavior should be to output to the INFO window, possibly with prefixed # or similar so that operator code copy/paste isn't broken.
  • A setting in User Preferences that changes your default logging level for all loggers created by the bpy.getLogger function. Possibly also a setting to redirect to stdout/stderr instead, or even to a remote logger. This could be done with a plugin, possibly.
  • Code templates within blender, and examples in the manual should use this style.

These proposals would, I believe, add enough obvious easy benefits to mean more people would use the logging system from the beginning, while additionally giving more power to plugin developers.

100%

Development Status: Open

Upvote 3 Downvote 0
danthedeckie
1 Nov 2016

1 Comment

romboutv

He also wrote this article code.blender.org/2016/05/logging-from-python-code-in-blender/ I think its up to the dev how to use it. Since logging is all about customization, every project is different. You can log whatever you want.