Adjust SYS_LOG_PATTERN to parse single digit day number
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 8 Nov 2022 08:57:02 +0000 (09:57 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 8 Nov 2022 08:57:02 +0000 (09:57 +0100)
Noticed by this failing unit test:

FAIL: test_parse_messages (test_log_read.LogReadTester)
Try parsing first 100 lines of messages if running on linux
----------------------------------------------------------------------
Traceback (most recent call last):
  File "pyi2ncommon/test/test_log_read.py", line 268, in test_parse_messages
    self.assertIsNotNone(data, f"Failed to parse {parser.last_unparsed_line}")
AssertionError: unexpectedly None : Failed to parse Nov  7 09:24:31 storm kernel: Linux version 6.0.5-200.fc36.x86_64 (mockbuild@bkernel02.iad2.fedoraproject.org) (gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2), GNU ld version 2.37-36.fc36) #1 SMP PREEMPT_DYNAMIC Wed Oct 26 15:55:21 UTC 2022

src/log_read.py

index 35e50c1..ca47eb9 100644 (file)
@@ -431,5 +431,5 @@ PROXY_LOG_PATTERN = \
 
 # pattern for linux system logs (usually "messages" or "syslog" also "maillog"
 SYS_LOG_PATTERN = \
-    r'\s*(?P<timestamp>\w{3} +\d{2} \d{2}:\d{2}:\d{2}) (?P<hostname>\S+) ' \
+    r'\s*(?P<timestamp>\w{3} +\d{1,2} \d{2}:\d{2}:\d{2}) (?P<hostname>\S+) ' \
     + r'(?P<procname>[^\[\]:]+)(?:\[(?P<pid>\d+)\])?: (?P<message>.*)'