Skip to content

Commit

Permalink
provide a way to truncate the error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
𝐢𝐁𝐮𝐠 ♦ committed Nov 7, 2018
1 parent 1d96c4c commit 7da287c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions helpers.py
Expand Up @@ -37,6 +37,19 @@ def fetch_last(cls, n):
cls.db.close()
return data

@classmethod
def truncate(cls, n=100):
"""
Truncate the DB and keep only N latest exceptions
"""
cls.db = sqlite3.connect("errorLogs.db")
cursor = cls.db.execute(
"DELETE FROM error_logs WHERE time IN "
"(SELECT time FROM error_logs ORDER BY time DESC LIMIT -1 OFFSET ?)", (int(n),))
data = cursor.fetchall()
cls.db.close()
return data


class Helpers:
min_log_level = 0
Expand Down

0 comments on commit 7da287c

Please sign in to comment.