Skip to content

Commit 27950d8

Browse files
author
rgoliver
authored
Roll Pigweed and update console (project-chip#8643)
- Roll Pigweed to: b44d95e599b - Added ESP log formating to console
1 parent 5da31a9 commit 27950d8

File tree

2 files changed

+23
-4
lines changed
  • examples/common/pigweed/rpc_console/py/chip_rpc
  • third_party/pigweed

2 files changed

+23
-4
lines changed

examples/common/pigweed/rpc_console/py/chip_rpc/console.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
"""
3838

3939
import argparse
40+
from collections import namedtuple
4041
import logging
4142
import sys
4243
from typing import Any, BinaryIO
4344
import socket
4445
from inspect import cleandoc
4546
import serial # type: ignore
46-
47+
import re
4748
import pw_cli.log
4849
from pw_console.console_app import embed
4950
from pw_console.__main__ import create_temp_log_file
@@ -149,9 +150,27 @@ def read(self, num_bytes: int = PW_RPC_MAX_PACKET_SIZE):
149150
def write_to_output(data: bytes,
150151
unused_output: BinaryIO = sys.stdout.buffer,):
151152
log_line = data
152-
153+
RegexStruct = namedtuple('RegexStruct', 'platform type regex match_num')
154+
LEVEL_MAPPING = {"I": logging.INFO, "W": logging.WARNING,
155+
"E": logging.ERROR, "F": logging.FATAL, "V": logging.DEBUG, "D": logging.DEBUG}
156+
ESP_CHIP_REGEX = r"(?P<level>[IWEFV]) \((?P<time>\d+)\) (?P<mod>chip\[[a-zA-Z]+\]):\s(?P<msg>.*)"
157+
ESP_APP_REGEX = r"(?P<level>[IWEFVD]) \((?P<time>\d+)\) (?P<mod>[a-z\-_A-Z]+):\s(?P<msg>.*)"
158+
LogRegexes = [RegexStruct("ESP", "CHIP", re.compile(ESP_CHIP_REGEX), 4),
159+
RegexStruct("ESP", "APP", re.compile(ESP_APP_REGEX), 4)
160+
]
153161
for line in log_line.decode(errors="surrogateescape").splitlines():
154-
_DEVICE_LOG.info(line)
162+
fields = {'level': logging.INFO, "time": "",
163+
"mod": "", "type": "", "msg": line}
164+
for log_regex in LogRegexes:
165+
match = log_regex.regex.search(line)
166+
if match and len(match.groups()) == log_regex.match_num:
167+
fields['type'] = log_regex.type
168+
fields.update(match.groupdict())
169+
if "level" in match.groupdict():
170+
fields["level"] = LEVEL_MAPPING[fields["level"]]
171+
break
172+
_DEVICE_LOG.log(fields["level"], fields["msg"], extra={'extra_metadata_fields': {
173+
"time": fields["time"], "type": fields["type"], "mod": fields["mod"]}})
155174

156175

157176
def console(device: str, baudrate: int,

third_party/pigweed/repo

Submodule repo updated 234 files

0 commit comments

Comments
 (0)