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

[Python] Make Logging Filtering global #31944

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ shared_library("ChipDeviceCtrl") {
"chip/internal/ChipThreadWork.cpp",
"chip/internal/ChipThreadWork.h",
"chip/internal/CommissionerImpl.cpp",
"chip/logging/LoggingFilter.cpp",
"chip/logging/LoggingRedirect.cpp",
"chip/native/ChipMainLoopWork.h",
"chip/native/PyChipError.cpp",
Expand Down
20 changes: 0 additions & 20 deletions src/controller/python/ChipDeviceController-ScriptBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/DLLUtil.h>
#include <lib/support/ScopedBuffer.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/QRCodeSetupPayloadParser.h>
#include <system/SystemClock.h>
Expand Down Expand Up @@ -200,9 +199,6 @@ PyChipError pychip_ScriptDevicePairingDelegate_SetOpenWindowCompleteCallback(
// BLE
PyChipError pychip_DeviceCommissioner_CloseBleConnection(chip::Controller::DeviceCommissioner * devCtrl);

uint8_t pychip_DeviceController_GetLogFilter();
void pychip_DeviceController_SetLogFilter(uint8_t category);

const char * pychip_Stack_ErrorToString(ChipError::StorageType err);
const char * pychip_Stack_StatusReportToString(uint32_t profileId, uint16_t statusCode);
void pychip_Stack_SetLogFunct(LogMessageFunct logFunct);
Expand Down Expand Up @@ -353,22 +349,6 @@ const char * pychip_DeviceController_StatusReportToString(uint32_t profileId, ui
return nullptr;
}

uint8_t pychip_DeviceController_GetLogFilter()
{
#if _CHIP_USE_LOGGING
return chip::Logging::GetLogFilter();
#else
return chip::Logging::kLogCategory_None;
#endif
}

void pychip_DeviceController_SetLogFilter(uint8_t category)
{
#if _CHIP_USE_LOGGING
chip::Logging::SetLogFilter(category);
#endif
}

PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissioner * devCtrl, uint16_t discriminator,
uint32_t setupPINCode, chip::NodeId nodeid)
{
Expand Down
17 changes: 0 additions & 17 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,23 +1476,6 @@ def ZCLAttributeList(self):

return self._Cluster.ListClusterAttributes()

def SetLogFilter(self, category):
self.CheckIsActive()

if category < 0 or category > pow(2, 8):
raise ValueError("category must be an unsigned 8-bit integer")

self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_SetLogFilter(category)
)

def GetLogFilter(self):
self.CheckIsActive()

self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_GetLogFilter()
)

def SetBlockingCB(self, blockingCB):
self.CheckIsActive()

Expand Down
37 changes: 37 additions & 0 deletions src/controller/python/chip/logging/LoggingFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <lib/support/logging/CHIPLogging.h>

extern "C" {

uint8_t pychip_logging_GetLogFilter()
{
#if _CHIP_USE_LOGGING
return chip::Logging::GetLogFilter();
#else
return chip::Logging::kLogCategory_None;
#endif
}

void pychip_logging_SetLogFilter(uint8_t category)
{
#if _CHIP_USE_LOGGING
chip::Logging::SetLogFilter(category);
#endif
}
}
13 changes: 13 additions & 0 deletions src/controller/python/chip/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ def RedirectToPythonLogging():

handle = _GetLoggingLibraryHandle()
handle.pychip_logging_set_callback(_RedirectToPythonLogging)


def SetLogFilter(category):
if category < 0 or category > pow(2, 8):
raise ValueError("category must be an unsigned 8-bit integer")

handle = _GetLoggingLibraryHandle()
handle.pychip_logging_SetLogFilter(category)


def GetLogFilter():
handle = _GetLoggingLibraryHandle()
return handle.pychip_logging_GetLogFilter()
2 changes: 1 addition & 1 deletion src/platform/Linux/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;
#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS

#ifndef CHIP_LOG_FILTERING
#define CHIP_LOG_FILTERING 0
#define CHIP_LOG_FILTERING 1
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
#endif // CHIP_LOG_FILTERING

#ifndef CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS
Expand Down
Loading