Changeset 11189 in ntrip for trunk/BNC/tests/tools


Ignore:
Timestamp:
Nov 10, 2026, 8:45:57 AM (33 hours ago)
Author:
stuerze
Message:

Structured logging improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/tests/tools/logcheck.py

    r11187 r11189  
    77logfmt file a sequence of key=value pairs, that both carry the same records,
    88that the records have the mandatory keys in the documented order (optional
    9 'epoch' after 'time', GPS Time without 'Z'), that the 'msg' of the records
    10 (for RTCM scan message types: 'mp', 'message_type', 'size') equals the text of
    11 the classic logfile line by line (classic lines without
    12 their "yy-mm-dd hh:mm:ss " prefix; the start line is skipped, it goes to the
    13 file of the current date) and that 'time' (UTC) is the GPS Time stamp of the
    14 classic line minus the GPS-UTC leap seconds. Prints a summary of the records per level,
    15 component and event; exit code 1 on any error.
     9'epoch' after 'time', GPS Time without 'Z'), that the records belong line by
     10line to the classic logfile ('msg' is the classic text without the "<mp>: "
     11prefix, shortened for events whose fields carry the details, see matches();
     12classic lines without their "yy-mm-dd hh:mm:ss " prefix; the start line is
     13skipped, it goes to the file of the current date) and that 'time' (UTC) is the
     14GPS Time stamp of the classic line minus the GPS-UTC leap seconds. Prints a
     15summary of the records per level, component and event; exit code 1 on any
     16error.
    1617"""
    1718
    … …  
    7071
    7172
    72 def classic_text(r):
    73     """Text of the classic logfile line of a record: 'msg', except for the
    74     message types of the RTCM scan, which carry the short text 'Received message'
    75     and the details in their fields."""
    76     if r.get("event") == "stream_content" and "message_type" in r:
    77         if r["msg"] != "Received message":
    78             return "unexpected msg %r" % r["msg"]
     73# events with a short structured 'msg': prefix the classic line must start with
     74SHORT = {
     75    "ppp_position": lambda r: "%s %s X = " % (r["epoch"].replace("T", "_"), r["mp"]),
     76    "stream_latency": lambda r: "%s %s: Mean latency " % (r["mp"], r["type"]),
     77}
     78
     79
     80def matches(r, line):
     81    """Does the record belong to the classic logfile line? The structured 'msg'
     82    is the classic text without the "<mp>: " prefix, shortened where the
     83    fields carry the details."""
     84    mp, msg, ev = r.get("mp"), r.get("msg"), r.get("event")
     85    if ev in SHORT:
     86        return line.startswith(SHORT[ev](r))
     87    if ev == "stream_content" and "message_type" in r:
    7988        size = " (size %d)" % r["size"] if "size" in r else " "
    80         return "%s: Received message type %d%s" % (r["mp"], r["message_type"], size)
    81     return r.get("msg")
     89        return msg == "Received message" and \
     90            line == "%s: Received message type %d%s" % (mp, r["message_type"], size)
     91    if mp and line.startswith(mp + ": "):
     92        line = line[len(mp) + 2:]
     93    if ev.startswith("stream_outage_") or ev.startswith("stream_corrupted_"):
     94        return line.startswith(msg + " ")
     95    return msg == line
    8296
    8397
    … …  
    134148
    135149    body = [r for r in recs if "========== Start BNC" not in r.get("msg", "")]
    136     msgs = [classic_text(r) for r in body]
    137150    for k, (r, st) in enumerate(zip(body, stamps), 1):
    138151        utc = datetime.datetime.strptime(r["time"], "%Y-%m-%dT%H:%M:%S.%fZ")
    139152        if st is not None and (st - utc.replace(microsecond=0)).total_seconds() != LEAP_GPS_UTC:
    140153            errors.append("record %d: time %s, classic %s" % (k, r["time"], st))
    141     if msgs != classic:
    142         for k, (a, b) in enumerate(zip(msgs, classic), 1):
    143             if a != b:
    144                 errors.append("record %d: msg %r, classic %r" % (k, a, b))
    145                 break
    146         else:
    147             errors.append("%d records, %d classic lines" % (len(msgs), len(classic)))
     154    for k, (r, line) in enumerate(zip(body, classic), 1):
     155        if not matches(r, line):
     156            errors.append("record %d: msg %r, classic %r" % (k, r.get("msg"), line))
     157            break
     158    if len(body) != len(classic):
     159        errors.append("%d records, %d classic lines" % (len(body), len(classic)))
    148160
    149161    print("%d records" % len(recs))
Note: See TracChangeset for help on using the changeset viewer.