You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FYI I've already changed the argument name from "logname" to "path" which is shorter and better reflects the pathlib.Path syntax elsewhere in log2d. Hope that's ok Mike?
Anyhow... this enhancement is to change the way you access other log files. Your original solution requires people to create an instance of the Log class first and give it a name. I think a better and conceptually better approach would be for people to type:
Log.find(path="another_log_file.log")
or in other words make it a Class method. This might be tricky to implement because we want a .find method for individual instances too - we might have to rename it e.g. Log.find_in("another_log_file.log") and be clever about reusing the core search logic between the class method and the instance method.
If you're not familiar with class versus instance methods I appreciate this isn't going to make much sense!
Here's the test I added to test_log2d.py:
def test_find_path():
create_dummy_log()
result = Log.find(path="mylog.log", date=timestamp, deltadays=-3)
assert len(result) == 6, f"FIND14: Anotherlog - Expected 6 lines found {len(result)}"
The text was updated successfully, but these errors were encountered:
I've got a decorator sorted that works with the current find but - spookily (?) - find works as-is if you set a default value for self, thus:
def find(self=None, text: str="", path=None,...
This seems to work fine for
Mylog = Log('mylog', to_file=True)
result = MyLog.find()
# and
result = Log.find('mylog')
# and
result = Log("").find('mylog')
I can find nothing about this approach, so I'm a little worried in case it breaks something in python - it has the feel of quick-and-dirty about it, so I'm inclined to use the standard decorator approach. Any comments?
FYI I've already changed the argument name from "logname" to "path" which is shorter and better reflects the pathlib.Path syntax elsewhere in log2d. Hope that's ok Mike?
Anyhow... this enhancement is to change the way you access other log files. Your original solution requires people to create an instance of the Log class first and give it a name. I think a better and conceptually better approach would be for people to type:
or in other words make it a Class method. This might be tricky to implement because we want a .find method for individual instances too - we might have to rename it e.g. Log.find_in("another_log_file.log") and be clever about reusing the core search logic between the class method and the instance method.
If you're not familiar with class versus instance methods I appreciate this isn't going to make much sense!
Here's the test I added to test_log2d.py:
The text was updated successfully, but these errors were encountered: