Skip to content

Commit b790232

Browse files
authored
[Python] Add "automation" level to log defines (#33670)
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 60b7215 commit b790232

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
@@ -36,6 +36,7 @@
3636
from threading import Condition, Event, Lock
3737

3838
import chip.native
39+
from chip.logging import LOG_CATEGORY_AUTOMATION, LOG_CATEGORY_DETAIL, LOG_CATEGORY_ERROR, LOG_CATEGORY_PROGRESS
3940
from chip.native import PyChipError
4041

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

81-
# NOTE: These values must correspond to those used in the chip C++ code.
82-
Disabled = 0
83-
Error = 1
84-
Progress = 2
85-
Detail = 3
86-
Retain = 4
87-
8882
@staticmethod
8983
def categoryToLogLevel(cat):
90-
if cat == LogCategory.Error:
84+
if cat == LOG_CATEGORY_ERROR:
9185
return logging.ERROR
92-
elif cat == LogCategory.Progress:
86+
elif cat == LOG_CATEGORY_PROGRESS:
9387
return logging.INFO
94-
elif cat == LogCategory.Detail:
88+
elif cat in (LOG_CATEGORY_DETAIL, LOG_CATEGORY_AUTOMATION):
9589
return logging.DEBUG
96-
elif cat == LogCategory.Retain:
97-
return logging.CRITICAL
9890
else:
9991
return logging.NOTSET
10092

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)