Skip to content

Commit

Permalink
Roll Pigweed and update console (#8643)
Browse files Browse the repository at this point in the history
- Roll Pigweed to: b44d95e599b
- Added ESP log formating to console
  • Loading branch information
rgoliver authored and pull[bot] committed Aug 16, 2021
1 parent 85a3c73 commit 6552d3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions examples/common/pigweed/rpc_console/py/chip_rpc/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
"""

import argparse
from collections import namedtuple
import logging
import sys
from typing import Any, BinaryIO
import socket
from inspect import cleandoc
import serial # type: ignore

import re
import pw_cli.log
from pw_console.console_app import embed
from pw_console.__main__ import create_temp_log_file
Expand Down Expand Up @@ -149,9 +150,27 @@ def read(self, num_bytes: int = PW_RPC_MAX_PACKET_SIZE):
def write_to_output(data: bytes,
unused_output: BinaryIO = sys.stdout.buffer,):
log_line = data

RegexStruct = namedtuple('RegexStruct', 'platform type regex match_num')
LEVEL_MAPPING = {"I": logging.INFO, "W": logging.WARNING,
"E": logging.ERROR, "F": logging.FATAL, "V": logging.DEBUG, "D": logging.DEBUG}
ESP_CHIP_REGEX = r"(?P<level>[IWEFV]) \((?P<time>\d+)\) (?P<mod>chip\[[a-zA-Z]+\]):\s(?P<msg>.*)"
ESP_APP_REGEX = r"(?P<level>[IWEFVD]) \((?P<time>\d+)\) (?P<mod>[a-z\-_A-Z]+):\s(?P<msg>.*)"
LogRegexes = [RegexStruct("ESP", "CHIP", re.compile(ESP_CHIP_REGEX), 4),
RegexStruct("ESP", "APP", re.compile(ESP_APP_REGEX), 4)
]
for line in log_line.decode(errors="surrogateescape").splitlines():
_DEVICE_LOG.info(line)
fields = {'level': logging.INFO, "time": "",
"mod": "", "type": "", "msg": line}
for log_regex in LogRegexes:
match = log_regex.regex.search(line)
if match and len(match.groups()) == log_regex.match_num:
fields['type'] = log_regex.type
fields.update(match.groupdict())
if "level" in match.groupdict():
fields["level"] = LEVEL_MAPPING[fields["level"]]
break
_DEVICE_LOG.log(fields["level"], fields["msg"], extra={'extra_metadata_fields': {
"time": fields["time"], "type": fields["type"], "mod": fields["mod"]}})


def console(device: str, baudrate: int,
Expand Down
2 changes: 1 addition & 1 deletion third_party/pigweed/repo
Submodule repo updated 234 files

0 comments on commit 6552d3e

Please sign in to comment.