Page MenuHome

Add prototype for python logging api
Needs ReviewPublic

Authored by Mateusz Grzeliński (grzelins) on Aug 24 2020, 11:11 AM.

Details

Summary

The following code is part of implementation of T80072: Create python API for CLOG.
You can execute the following code, but:

  • log message, path is not copied, so expect memory violation
  • everything is logged to one logger
import bpy  # in design it is _bpy

bpy.utils.log.error("err hello")
bpy.utils.log.warning("warn hello")
bpy.utils.log.info("info hello")
bpy.utils.log.debug("debug hello")

# ----
import logging
import bpy
log = logging.getLogger("bpy.my_addon")  # add type for easy filtering in blender
log.addHandler(bpy.utils.log.LogHandler())
log.setLevel(logging.INFO) # default is WARNING

# ----
import bpy
import logging

log = bpy.utils.log.getLogger("bpy.my_addon")  # automatically add handler (can also set log level based on blener's log level)
log.setLevel(logging.INFO)

Diff Detail

Repository
rB Blender
Branch
python-api-log (branched from master)
Build Status
Buildable 9746
Build 9746: arc lint + arc unit

Event Timeline

Mateusz Grzeliński (grzelins) requested review of this revision.Aug 24 2020, 11:11 AM
Mateusz Grzeliński (grzelins) created this revision.
Campbell Barton (campbellbarton) requested changes to this revision.Aug 25 2020, 2:22 AM

Initial review.

Note, we could expose this via bpy.app.log since this logs at the application level and isn't so much a utility function, although this isn't an urgent decision at this point.

release/scripts/modules/bpy/utils/log.py
27

getLogger is missing.

source/blender/python/intern/bpy_log.c
31

Don't we want Python to be able to define it's own ID's instead of using bpy.log for all?

50

_PyArg_ParseTupleAndKeywordsFast can be used here for faster parsing (avoid evaluating the format string every time).

64–70

Use PyErr_Format.

74–76

Use PyErr_Format.

This revision now requires changes to proceed.Aug 25 2020, 2:22 AM
Mateusz Grzeliński (grzelins) edited the summary of this revision. (Show Details)
  • apply review suggestions
  • use multiple log types for python log api - logging to one log was temporary solution
    • I am not sure about performance of introduced solution, we can always separate registering log type from sending log message
    • do we need unregister mechanism?
Mateusz Grzeliński (grzelins) marked 5 inline comments as done.Aug 25 2020, 9:47 AM