Create python API for CLOG #80072

Open
opened 2020-08-24 11:28:25 +02:00 by Mateusz Grzeliński · 7 comments

Status: Prototype is created but design is not set


Description
Big picture: Remove print functions from blender .py files, add integrate python logging module with blender info editor

Use cases:

  • there are many small python files with print, that reports error. This error can be tricky to track down, as path and line is not appended
  • reduce usage of system console
  • for addon developers to have nice feedback

Design:

  • use python built in logging module as much as posible
  • expose blender logging as handler bpy.utils.LogHandler. Loghandler inherits logging.Handler and is fully functional python class.

optional: expose individual log utilities for quick and easy: bpy.utils.info("message"), bpy.utils.warning and so on

Log integration would be enabled like any other blender log: --log "bke.*,bpy.my_addon"

Engineer plan:

  • Minimal use case:
    ** any log related UI is left for addon developer. If addon developer wants to expose log level in his user preferences, he will create separate property by himself.
import logging
import bpy
log = logging.getLogger("bpy.my_addon")  # add type for easy filtering in blender
log.addhandler(bpy.utils.log.LogHandler())  # integrate with blender
log.setLevel(logging.INFO)  # the rest of pythonic stuff
  • small extension for blender internal use:
import _bpy # hide it from users

# for blender internal usage, quick and easy, but always logs to "bpy.log"
_bpy.utils.log.error("hello")
_bpy.utils.log.warning("hello")
_bpy.utils.log.info("hello")
_bpy.utils.log.debug("hello")
  • experimental, requires more design: deeper integration with blender
    automatically add handler inherit blender log settings
    **
import bpy
import logging

log = bpy.utils.log.getLogger("bpy.my_addon")  # automatically add handler, inherit blender log settings and other magic
log.setLevel(logging.INFO)  # this becomes problematic as it conflicts with blender settings

=====Work plan=====

In order to utilize new filtering features available in info editor:

  • [] python log name must correspond to new CLG_LogType. Currently log types are stored in list what will not be efficient enough.
  • [] CLG_LogRecord assumes that file path is const char and python gives us path which need to be copied. Where to store that memory?
  • [] can we use global log context or do we need to create new one?

Minimal implementation is done in {D8688} but not all issues are solved.

{F8807983}

**Status:** Prototype is created but design is not set --- **Description** **Big picture:** Remove `print` functions from blender `.py` files, add integrate python `logging` module with blender info editor **Use cases**: * there are many small python files with print, that reports error. This error can be tricky to track down, as path and line is not appended * reduce usage of system console * for addon developers to have nice feedback **Design:** - use python built in `logging` module as much as posible - expose blender logging as handler `bpy.utils.LogHandler`. `Loghandler` inherits `logging.Handler` and is fully functional python class. # optional: expose individual log utilities for quick and easy: `bpy.utils.info("message")`, `bpy.utils.warning` and so on Log integration would be enabled like any other blender log: `--log "bke.*,bpy.my_addon"` **Engineer plan:** * Minimal use case: ** any log related UI is left for addon developer. If addon developer wants to expose log level in his user preferences, he will create separate property by himself. ```lang=python import logging import bpy log = logging.getLogger("bpy.my_addon") # add type for easy filtering in blender log.addhandler(bpy.utils.log.LogHandler()) # integrate with blender log.setLevel(logging.INFO) # the rest of pythonic stuff ``` * small extension for blender internal use: ```lang=python import _bpy # hide it from users # for blender internal usage, quick and easy, but always logs to "bpy.log" _bpy.utils.log.error("hello") _bpy.utils.log.warning("hello") _bpy.utils.log.info("hello") _bpy.utils.log.debug("hello") ``` * experimental, requires more design: deeper integration with blender **automatically add handler** inherit blender log settings ** ```lang=python import bpy import logging log = bpy.utils.log.getLogger("bpy.my_addon") # automatically add handler, inherit blender log settings and other magic log.setLevel(logging.INFO) # this becomes problematic as it conflicts with blender settings ``` =====Work plan===== In order to utilize new filtering features available in info editor: - [] python log name must correspond to new `CLG_LogType`. Currently log types are stored in list what will not be efficient enough. - [] `CLG_LogRecord` assumes that file path is `const char` and python gives us path which need to be copied. Where to store that memory? - [] can we use global log context or do we need to create new one? Minimal implementation is done in {D8688} but not all issues are solved. {F8807983}
Mateusz Grzeliński self-assigned this 2020-08-24 11:28:25 +02:00
Author
Member

Added subscriber: @grzelins

Added subscriber: @grzelins

Added subscriber: @StephenSwaney

Added subscriber: @StephenSwaney

Added subscriber: @elfoglalt

Added subscriber: @elfoglalt

Added subscriber: @ckohl_art

Added subscriber: @ckohl_art
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'
Member

Guess that needs #python_api devs to decide if this should be confirmed.

Guess that needs #python_api devs to decide if this should be confirmed.
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:24:10 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#80072
No description provided.