Skip to content

Commit 1e447cb

Browse files
committed
also store raw log messages in the slog file.
1 parent 462d9a8 commit 1e447cb

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"request": "launch",
205205
"module": "meshtastic",
206206
"justMyCode": false,
207-
"args": ["--slog", "--power-ppk2-meter", "--power-stress", "--power-voltage", "3.3", "--seriallog"]
207+
"args": ["--slog", "--power-ppk2-meter", "--power-stress", "--power-voltage", "3.3", "--seriallog", "--ble"]
208208
},
209209
{
210210
"name": "meshtastic test",

meshtastic/slog/slog.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class StructuredLogger:
110110
"""Sniffs device logs for structured log messages, extracts those into apache arrow format.
111111
Also writes the raw log messages to raw.txt"""
112112

113-
def __init__(self, client: MeshInterface, dir_path: str) -> None:
113+
def __init__(self, client: MeshInterface, dir_path: str, include_raw=True) -> None:
114114
"""Initialize the StructuredLogger object.
115115
116116
client (MeshInterface): The MeshInterface object to monitor.
@@ -123,6 +123,10 @@ def __init__(self, client: MeshInterface, dir_path: str) -> None:
123123
(lambda x, y: x + y), map(lambda x: x.fields, log_defs.values())
124124
)
125125

126+
self.include_raw = include_raw
127+
if self.include_raw:
128+
all_fields.append(("raw", pa.string()))
129+
126130
self.writer.set_schema(pa.schema(all_fields))
127131

128132
self.raw_file: Optional[
@@ -151,6 +155,9 @@ def _onLogMessage(self, line: str) -> None:
151155
152156
line (str): the line of log output
153157
"""
158+
159+
di = {} # the dictionary of the fields we found to log
160+
154161
m = log_regex.match(line)
155162
if m:
156163
src = m.group(1)
@@ -163,13 +170,18 @@ def _onLogMessage(self, line: str) -> None:
163170
r = d.format.parse(args) # get the values with the correct types
164171
if r:
165172
di = r.named
166-
di["time"] = datetime.now()
167-
self.writer.add_row(di)
168173
else:
169174
logging.warning(f"Failed to parse slog {line} with {d.format}")
170175
else:
171176
logging.warning(f"Unknown Structured Log: {line}")
172177

178+
# Store our structured log record
179+
if di or self.include_raw:
180+
di["time"] = datetime.now()
181+
if self.include_raw:
182+
di["raw"] = line
183+
self.writer.add_row(di)
184+
173185
if self.raw_file:
174186
self.raw_file.write(line + "\n") # Write the raw log
175187

0 commit comments

Comments
 (0)