Source code for models.model_log_activity

"""
The model_log_activity class is responsible for configuring logging settings and creating log files for the application
"""
import logging
import os


[docs] class ModelLog: """ Class responsible for configuring logging settings and creating log files for the application. Attribute: _model (object): The main model instance of the application. Method: create_log_file(): Configures the logging settings and creates the log file. """ def __init__(self, model): self._model = model self.create_log_file()
[docs] def create_log_file(self): """ Configures the logging settings and creates the log file. This method sets up the format of log messages, the logging level, and the destination log file. If the application is reopening with an existing media source, it appends to the existing log file; otherwise, it creates a new log file. It also creates a logger instance for the application. """ # Configure logging filemode = "a" if self._model.main_config["Media_path"] is not None else "w" path_file = os.path.dirname(os.path.realpath(__file__)) logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename=f"{path_file}/cached/app_activity.log", filemode=filemode) # Create a logger instance self._model.activity_logger = logging.getLogger(__name__) # self._model._model_log.create_logging__model(self._model.logger_app_activity) if self._model.main_config["Media_path"] is not None: self._model.activity_logger.info('<<<<<<<<<<< Reopen the application begin here >>>>>>>>>>') self._model.activity_logger.info('The application is running, maintaining continuity with ' 'the media and configuration history.') if not self._model.debug_mode: self._model.activity_logger.info( 'Debug mode has been turned off, thus the application will not save the event history.') else: self._model.activity_logger.info('<<<<<<<<<<< Restarting the application >>>>>>>>>>') self._model.activity_logger.info('MoilApp has been successfully opened.')