Skip to content

Commit d8e32fe

Browse files
committed
[Python] Add "automation" level to log defines
So far the automation log level was missing. Add it to the log level defines in the logging module. While at it, also rename to LOG_CATEGORY (instead of ERROR_CATEGORY) and remove duplicated log level definitions in ChipStack.
1 parent 3c47f80 commit d8e32fe

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/controller/python/chip/ChipStack.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from threading import Condition, Event, Lock
3838

3939
import chip.native
40+
from chip.logging import LOG_CATEGORY_AUTOMATION, LOG_CATEGORY_DETAIL, LOG_CATEGORY_ERROR, LOG_CATEGORY_PROGRESS
4041
from chip.native import PyChipError
4142

4243
from .ChipUtility import ChipUtility
@@ -79,23 +80,14 @@ class DeviceStatusStruct(Structure):
7980
class LogCategory(object):
8081
"""Debug logging categories used by chip."""
8182

82-
# NOTE: These values must correspond to those used in the chip C++ code.
83-
Disabled = 0
84-
Error = 1
85-
Progress = 2
86-
Detail = 3
87-
Retain = 4
88-
8983
@staticmethod
9084
def categoryToLogLevel(cat):
91-
if cat == LogCategory.Error:
85+
if cat == LOG_CATEGORY_ERROR:
9286
return logging.ERROR
93-
elif cat == LogCategory.Progress:
87+
elif cat == LOG_CATEGORY_PROGRESS:
9488
return logging.INFO
95-
elif cat == LogCategory.Detail:
89+
elif cat in (LOG_CATEGORY_DETAIL, LOG_CATEGORY_AUTOMATION):
9690
return logging.DEBUG
97-
elif cat == LogCategory.Retain:
98-
return logging.CRITICAL
9991
else:
10092
return logging.NOTSET
10193

src/controller/python/chip/logging/__init__.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
from chip.logging.library_handle import _GetLoggingLibraryHandle
2020
from chip.logging.types import LogRedirectCallback_t
2121

22-
# Defines match support/logging/Constants.h (LogCategory enum)
23-
ERROR_CATEGORY_NONE = 0
24-
ERROR_CATEGORY_ERROR = 1
25-
ERROR_CATEGORY_PROGRESS = 2
26-
ERROR_CATEGORY_DETAIL = 3
22+
# Defines match src/lib/support/logging/Constants.h (LogCategory enum)
23+
LOG_CATEGORY_NONE = 0
24+
LOG_CATEGORY_ERROR = 1
25+
LOG_CATEGORY_PROGRESS = 2
26+
LOG_CATEGORY_DETAIL = 3
27+
LOG_CATEGORY_AUTOMATION = 4
2728

2829

2930
@LogRedirectCallback_t
@@ -34,11 +35,11 @@ def _RedirectToPythonLogging(category, module, message):
3435

3536
logger = logging.getLogger('chip.native.%s' % module)
3637

37-
if category == ERROR_CATEGORY_ERROR:
38+
if category == LOG_CATEGORY_ERROR:
3839
logger.error("%s", message)
39-
elif category == ERROR_CATEGORY_PROGRESS:
40+
elif category == LOG_CATEGORY_PROGRESS:
4041
logger.info("%s", message)
41-
elif category == ERROR_CATEGORY_DETAIL:
42+
elif category in (LOG_CATEGORY_DETAIL, LOG_CATEGORY_AUTOMATION):
4243
logger.debug("%s", message)
4344
else:
4445
# All logs are expected to have some reasonable category. This treats

0 commit comments

Comments
 (0)