Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize logging after native init #616

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions matter_server/server/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
CHIP_DETAIL = logging.DEBUG - 1
CHIP_AUTOMATION = logging.DEBUG - 2

_category_num: int = 4


@LogRedirectCallback_t # type: ignore[misc]
def _redirect_to_python_logging(
Expand Down Expand Up @@ -58,27 +60,24 @@ def init_logging(category: str) -> None:
"""Initialize Matter SDK logging. Filter by category."""

_LOGGER.info("Initializing CHIP/Matter Logging...")
category_num = ERROR_CATEGORY_NONE
_category_num = ERROR_CATEGORY_NONE
if category == "ERROR":
category_num = ERROR_CATEGORY_ERROR
_category_num = ERROR_CATEGORY_ERROR
elif category == "PROGRESS":
category_num = ERROR_CATEGORY_PROGRESS
_category_num = ERROR_CATEGORY_PROGRESS
elif category == "DETAIL":
category_num = ERROR_CATEGORY_DETAIL
_category_num = ERROR_CATEGORY_DETAIL
elif category == "AUTOMATION":
category_num = 4
_category_num = 4

logging.addLevelName(CHIP_ERROR, "CHIP_ERROR")
logging.addLevelName(CHIP_PROGRESS, "CHIP_PROGRESS")
logging.addLevelName(CHIP_DETAIL, "CHIP_DETAIL")
logging.addLevelName(CHIP_AUTOMATION, "CHIP_AUTOMATION")
logging.getLogger("chip.native").setLevel(CHIP_AUTOMATION)

handle = _GetLoggingLibraryHandle()
handle.pychip_logging_set_callback(_redirect_to_python_logging)

# Handle log level selection on SDK level
chip.logging.SetLogFilter(category_num)
# We can't setup logging here yet as the stack needs to be
# initialized first!


class MatterStack:
Expand All @@ -95,6 +94,14 @@ def __init__(
self.logger.debug("Using storage file: %s", storage_file)
chip.native.Init()

# Initialize logging after stack init!
# See: https://github.com/project-chip/connectedhomeip/issues/20233
handle = _GetLoggingLibraryHandle()
handle.pychip_logging_set_callback(_redirect_to_python_logging)

# Handle log level selection on SDK level
chip.logging.SetLogFilter(_category_num)

self._chip_stack = ChipStack(
persistentStoragePath=storage_file,
installDefaultLogHandler=False,
Expand Down