Skip to content

Commit

Permalink
remove recursion in logger to prevent too many recursions (#692)
Browse files Browse the repository at this point in the history
* Contributor: nicolasochem, Effort=1h
* Reviewer: jdsika, Effort=0h
  • Loading branch information
nicolasochem authored Feb 6, 2024
1 parent 5b5628c commit 24e06f1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/verbose_logging_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ def archive(self, path):
self.remove_oldest(archive_dir)

def remove_oldest(self, archive_dir):
files = [
os.path.join(archive_dir, f)
for f in os.listdir(archive_dir)
if self.is_archive_file(f)
]
sorted_files = sorted(files, key=os.path.getmtime)

if len(sorted_files) > self.keep_at_most:
os.remove(sorted_files[0])
self.remove_oldest(archive_dir)
while True:
files = [
os.path.join(archive_dir, f)
for f in os.listdir(archive_dir)
if self.is_archive_file(f)
]
sorted_files = sorted(files, key=os.path.getmtime)

if len(sorted_files) <= self.keep_at_most:
break # Exit the loop if the number of files is within the limit

os.remove(sorted_files[0]) # Remove the oldest file

def get_logger(self):
return self.logger
Expand Down

0 comments on commit 24e06f1

Please sign in to comment.