Browse Source

Fix incorrect auto-detection as timestamp log

TSLogParser was searching for any instance of [<number>] in a log
line, which was incorrectly matching on, eg:

  Sep 15 18:09:46 clgrabguye21.localdomain su[160015]: ...

With this change we assert that the timestamp occurs at the beginning
of the line.

Change-Id: I04da2f1fa661bccfd3b046dfc22e5a10f6cb37f8
Matthew Booth 1 year ago
parent
commit
e73a2a35b2
1 changed files with 5 additions and 1 deletions
  1. 5
    1
      oslogmerger/oslogmerger.py

+ 5
- 1
oslogmerger/oslogmerger.py View File

@@ -304,7 +304,8 @@ class TSLogParser(LogParser):
304 304
 
305 305
     @staticmethod
306 306
     def _read_timestamp(line):
307
-        start = line.index('[') + 1
307
+        # skip leading '['
308
+        start = 1
308 309
         end = line.index(']')
309 310
 
310 311
         if end < start:
@@ -347,6 +348,9 @@ class LogFile(object):
347 348
                     parser.parse_line(line)
348 349
 
349 350
                     # It worked!
351
+                    print('Detected %s as %s' %
352
+                          (filename, parser.__class__.__name__),
353
+                          file=sys.stderr)
350 354
                     return parser
351 355
                 except ValueError:
352 356
                     pass

Loading…
Cancel
Save