28
28
CHIP_DETAIL = logging .DEBUG - 1
29
29
CHIP_AUTOMATION = logging .DEBUG - 2
30
30
31
+ _category_num : int = 4
32
+
31
33
32
34
@LogRedirectCallback_t # type: ignore[misc]
33
35
def _redirect_to_python_logging (
@@ -58,27 +60,24 @@ def init_logging(category: str) -> None:
58
60
"""Initialize Matter SDK logging. Filter by category."""
59
61
60
62
_LOGGER .info ("Initializing CHIP/Matter Logging..." )
61
- category_num = ERROR_CATEGORY_NONE
63
+ _category_num = ERROR_CATEGORY_NONE
62
64
if category == "ERROR" :
63
- category_num = ERROR_CATEGORY_ERROR
65
+ _category_num = ERROR_CATEGORY_ERROR
64
66
elif category == "PROGRESS" :
65
- category_num = ERROR_CATEGORY_PROGRESS
67
+ _category_num = ERROR_CATEGORY_PROGRESS
66
68
elif category == "DETAIL" :
67
- category_num = ERROR_CATEGORY_DETAIL
69
+ _category_num = ERROR_CATEGORY_DETAIL
68
70
elif category == "AUTOMATION" :
69
- category_num = 4
71
+ _category_num = 4
70
72
71
73
logging .addLevelName (CHIP_ERROR , "CHIP_ERROR" )
72
74
logging .addLevelName (CHIP_PROGRESS , "CHIP_PROGRESS" )
73
75
logging .addLevelName (CHIP_DETAIL , "CHIP_DETAIL" )
74
76
logging .addLevelName (CHIP_AUTOMATION , "CHIP_AUTOMATION" )
75
77
logging .getLogger ("chip.native" ).setLevel (CHIP_AUTOMATION )
76
78
77
- handle = _GetLoggingLibraryHandle ()
78
- handle .pychip_logging_set_callback (_redirect_to_python_logging )
79
-
80
- # Handle log level selection on SDK level
81
- chip .logging .SetLogFilter (category_num )
79
+ # We can't setup logging here yet as the stack needs to be
80
+ # initialized first!
82
81
83
82
84
83
class MatterStack :
@@ -95,6 +94,14 @@ def __init__(
95
94
self .logger .debug ("Using storage file: %s" , storage_file )
96
95
chip .native .Init ()
97
96
97
+ # Initialize logging after stack init!
98
+ # See: https://github.com/project-chip/connectedhomeip/issues/20233
99
+ handle = _GetLoggingLibraryHandle ()
100
+ handle .pychip_logging_set_callback (_redirect_to_python_logging )
101
+
102
+ # Handle log level selection on SDK level
103
+ chip .logging .SetLogFilter (_category_num )
104
+
98
105
self ._chip_stack = ChipStack (
99
106
persistentStoragePath = storage_file ,
100
107
installDefaultLogHandler = False ,
0 commit comments