diff --git a/changelog.txt b/changelog.txt index 1a2d7a2..73b2ae5 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2025.08.19: +. Improved log trimming. + 2025.08.18: . Database handling optimization. diff --git a/exchange_wrapper.py b/exchange_wrapper.py index 9d341df..1e7c1d0 100755 --- a/exchange_wrapper.py +++ b/exchange_wrapper.py @@ -1,3 +1,4 @@ +import collections import time import credentials import sqlite3 @@ -1056,14 +1057,18 @@ class Logger: self.exchange_name = self.broker_config["exchange"] self.tg_credentials = credentials.get_credentials("telegram") self.log_list_max_length = 10 + self.log_list = collections.deque(maxlen=self.log_list_max_length) self.log_list = self.preload_logs() def preload_logs(self): try: with open(f"logs/{self.exchange_name}.log","r") as f: - self.log_list = f.readlines() - return self.log_list[-self.log_list_max_length:] + for line in f: + self.log_list.append(line.rstrip("\n")) + # self.log_list = f.readlines() + #return self.log_list[-self.log_list_max_length:] + return list(self.log_list) except Exception as e: print(e) return [] @@ -1132,7 +1137,7 @@ class Logger: self.log_list.append(text) #Trim log list - self.log_list = self.log_list[-self.log_list_max_length:] + #self.log_list = self.log_list[-self.log_list_max_length:] except Exception as e: print("Can't write log file") diff --git a/main.py b/main.py index 738296d..6c21d67 100644 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ import exchange_wrapper import trader -version = "2025.08.18" +version = "2025.08.19" ''' Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors