add timestamp to log files in log file folder and allow to download current logfile under windows

This commit is contained in:
avollkopf 2024-06-01 19:14:56 +02:00
parent e7c7d85731
commit 14e0190bb9
3 changed files with 14 additions and 2 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.1.a15"
__version__ = "4.4.1.a16"
__codename__ = "Yeast Starter"

View file

@ -287,7 +287,9 @@ def main(context, config_folder_path, logs_folder_path, debug_log_level):
logger.info(f"logs folder '{logs_folder_path}' doesnt exist and we are trying to create it")
pathlib.Path(logs_folder_path).mkdir(parents=True, exist_ok=True)
logger.info(f"logs folder '{logs_folder_path}' successfully created")
logger.addHandler(logging.handlers.RotatingFileHandler(os.path.join(logs_folder_path, f"cbpi.log"), maxBytes=1000000, backupCount=3))
handler=logging.handlers.RotatingFileHandler(os.path.join(logs_folder_path, f"cbpi.log"), maxBytes=1000000, backupCount=3)
logger.addHandler(handler)
handler.setFormatter(formatter)
except Exception as e:
logger.warning("log folder or log file could not be created or accessed. check folder and file permissions or create the logs folder somewhere you have access with a start option like '--log-folder-path=./logs'")
logging.critical(e, exc_info=True)

View file

@ -31,6 +31,7 @@ class SystemController:
self.cbpi = cbpi
self.service = cbpi.actor
self.logger = logging.getLogger(__name__)
self.logsFolderPath = self.cbpi.config_folder.logsFolderPath
self.cbpi.app.on_startup.append(self.check_for_update)
@ -111,6 +112,15 @@ class SystemController:
for entry in j:
result.append(entry['MESSAGE'])
else:
try:
logfilename=pathlib.Path(self.logsFolderPath+"/"+"cbpi.log")
with open(logfilename) as f:
for line in f:
result.append(line.rstrip('\n'))
except:
pass
try:
with open(fullname, 'w') as f:
for line in result: