log2d icon indicating copy to clipboard operation
log2d copied to clipboard

.find fails when format doesn't include Log Level

Open PFython opened this issue 2 years ago • 1 comments

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?

PFython avatar Dec 14 '22 21:12 PFython

Fixed in pull request #17

MikeDP avatar Mar 28 '23 14:03 MikeDP