diff --git a/src/bonsai/bonsai/bim/module/debug/__init__.py b/src/bonsai/bonsai/bim/module/debug/__init__.py index 546f7ce8ca..c01cf03275 100644 --- a/src/bonsai/bonsai/bim/module/debug/__init__.py +++ b/src/bonsai/bonsai/bim/module/debug/__init__.py @@ -20,6 +20,7 @@ import bpy from . import ui, prop, operator classes = ( + operator.ChangeLogLevel, operator.ConvertToBlender, operator.CopyDebugInformation, operator.CreateAllShapes, diff --git a/src/bonsai/bonsai/bim/module/debug/operator.py b/src/bonsai/bonsai/bim/module/debug/operator.py index d9f4cde92a..f82be54787 100644 --- a/src/bonsai/bonsai/bim/module/debug/operator.py +++ b/src/bonsai/bonsai/bim/module/debug/operator.py @@ -1003,6 +1003,31 @@ class ToggleDetailedIOSLogs(bpy.types.Operator): return {"FINISHED"} +LogLevelType = Literal["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] + + +class ChangeLogLevel(bpy.types.Operator): + bl_idname = "bim.change_log_level" + bl_label = "Change Log Level " + bl_options = {"REGISTER", "UNDO"} + bl_description = "Change general log level across all Python code in Blender" + + log_level: bpy.props.EnumProperty( # pyright: ignore[reportRedeclaration] + name="Log Level", + items=((i, i, "") for i in get_args(LogLevelType)), + default="WARNING", + ) + + if TYPE_CHECKING: + log_level: LogLevelType + + def execute(self, context): + root = logging.getLogger() + root.setLevel(self.log_level) + self.report({"INFO"}, f"Log level changed to {self.log_level}.") + return {"FINISHED"} + + class RestartBlender(bpy.types.Operator): bl_idname = "bim.restart_blender" bl_label = "Restart Blender" diff --git a/src/bonsai/bonsai/bim/module/debug/ui.py b/src/bonsai/bonsai/bim/module/debug/ui.py index 14e257c40a..e18160d425 100644 --- a/src/bonsai/bonsai/bim/module/debug/ui.py +++ b/src/bonsai/bonsai/bim/module/debug/ui.py @@ -33,6 +33,7 @@ class BIM_PT_debug(Panel): def draw(self, context): assert self.layout layout = self.layout + assert (wm := bpy.context.window_manager) props = tool.Debug.get_debug_props() bim_props = tool.Blender.get_bim_props() @@ -83,6 +84,10 @@ class BIM_PT_debug(Panel): row = layout.row() row.operator("bim.toggle_detailed_ios_logs") + row = layout.row(align=True) + row.prop(wm.operator_properties_last(bpy.ops.bim.change_log_level.idname()), "log_level", text="") + row.operator("bim.change_log_level") + row = layout.row() row.operator("bim.restart_blender")