Skip to content

.find fails when format doesn't include Log Level #13

Description

@PFython

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions