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(orbpy.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 Preferencesthat changes your default logging level for all loggers created by thebpy.getLoggerfunction. 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.
1 Comment
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.