log2d
log2d copied to clipboard
.find fails when format doesn't include Log Level
Here's the test I added to test_log2d.py which currently fails:
def test_find_without_loglevel():
""" fmt may not include loglevel e.g. ERROR. Test that .find still works"""
fmt = Log.presets['name_and_time']
mylog = Log("mylog", to_file=True, mode="w", to_stdout=True, fmt=fmt)
mylog("This format has no log level")
assert len(mylog.find()) == 1
cleanup()
I think your approach for .find is based on the Log Level as separator. Sadly this isn't going to work for all formats. Maybe another approach is based on either or both of:
a) Passing the separator explicitly as an argument e.g. mylog.find(text="search for this", separator="|") b) We know what mylog.fmt is... perhaps we can derive the logic from this, at least for the 5 or so preset formats? c) Use a handful of regexes e.g. one to find a datetime element (if any), one to find loglevel, one to find log name? Then compare to see if they all start/end with the same character e.g. "|" which is likely to be the separator?
Fixed in pull request #17