diff --git a/config/logger/files/default.json5 b/config/logger/files/default.json5 index 402dd07..f28e510 100644 --- a/config/logger/files/default.json5 +++ b/config/logger/files/default.json5 @@ -2,9 +2,11 @@ // log_location points to the folder which will contain the logs for this automation run. // If it is left as "DEFAULT", then ~/AUTOMATION_LOGS will be used. "log_location": "DEFAULT", + "append_lab_and_timestamp": true, // appends the lab name and timestamp to the log file location // Acceptable values are: ERROR, WARNING, INFO, or DEBUG "console_log_level": "DEBUG", // Level of Logs displayed in the console. "file_log_level": "DEBUG", // Level of Logs included in log files. + } \ No newline at end of file diff --git a/config/logger/objects/logger_config.py b/config/logger/objects/logger_config.py index 1413ff2..67d3e36 100644 --- a/config/logger/objects/logger_config.py +++ b/config/logger/objects/logger_config.py @@ -46,6 +46,10 @@ class LoggerConfig: raise ValueError(f"The provided File Log Level is invalid. " f"Please select a value in {log_levels_map.keys()}.") self.file_log_level_value = log_levels_map[self.file_log_level] + self.append_lab_and_timestamp = True + if 'append_lab_and_timestamp' in log_dict: + self.append_lab_and_timestamp = log_dict['append_lab_and_timestamp'] + def get_log_location(self) -> str: """ Getter for the folder where we want to store the log files. @@ -99,6 +103,14 @@ class LoggerConfig: """ return self.file_log_level_value + def get_append_lab_and_timestamp(self) -> bool: + """ + Getter to see if we should append lab name and timestamp folders to the log file location + Returns: + + """ + return self.append_lab_and_timestamp + def to_log_strings(self) -> List[str]: """ This function will return a list of strings that can be logged to show all the logger configs. diff --git a/framework/logging/automation_logger.py b/framework/logging/automation_logger.py index 6553a35..2410ecc 100644 --- a/framework/logging/automation_logger.py +++ b/framework/logging/automation_logger.py @@ -125,8 +125,10 @@ def configure_logger(): _LOGGER = logging.getLogger('automation_log') # create the root folder and make the dirs - log_root_folder = logger_config.get_log_location() - _LOGGER.log_folder = os.path.join(log_root_folder, lab_configuration.get_lab_name(), strftime('%Y%m%d%H%M')) + _LOGGER.log_folder = logger_config.get_log_location() + + if logger_config.get_append_lab_and_timestamp(): + _LOGGER.log_folder = os.path.join(_LOGGER.log_folder, lab_configuration.get_lab_name(), strftime('%Y%m%d%H%M')) os.makedirs(_LOGGER.log_folder, exist_ok=True) log_file = os.path.join(_LOGGER.get_log_folder(), "full_logs.txt")