Skip to content

Commit

Permalink
add timestamp to log files in log file folder and allow to download c…
Browse files Browse the repository at this point in the history
…urrent logfile under windows
  • Loading branch information
avollkopf committed Jun 1, 2024
1 parent e7c7d85 commit 14e0190
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.4.1.a15"
__version__ = "4.4.1.a16"
__codename__ = "Yeast Starter"

4 changes: 3 additions & 1 deletion cbpi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions cbpi/controller/system_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, cbpi):
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)

Expand Down Expand Up @@ -111,6 +112,15 @@ async def downloadlog(self, logtime):

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:
Expand Down

0 comments on commit 14e0190

Please sign in to comment.