Allow user to override the appending of lab name and timestamp to log

Allow users to override the lab name and timestamp folder being
automatically created for log file locations

Change-Id: I76643c6a4c8ad1764dc7bdd0e6f23d49f720a457
This commit is contained in:
jpike 2024-12-05 13:43:47 -05:00
parent efba994855
commit 3ab1465d4d
3 changed files with 18 additions and 2 deletions

View File

@ -2,9 +2,11 @@
// log_location points to the folder which will contain the logs for this automation run. // 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. // If it is left as "DEFAULT", then ~/AUTOMATION_LOGS will be used.
"log_location": "DEFAULT", "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 // Acceptable values are: ERROR, WARNING, INFO, or DEBUG
"console_log_level": "DEBUG", // Level of Logs displayed in the console. "console_log_level": "DEBUG", // Level of Logs displayed in the console.
"file_log_level": "DEBUG", // Level of Logs included in log files. "file_log_level": "DEBUG", // Level of Logs included in log files.
} }

View File

@ -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()}.") 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.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: def get_log_location(self) -> str:
""" """
Getter for the folder where we want to store the log files. Getter for the folder where we want to store the log files.
@ -99,6 +103,14 @@ class LoggerConfig:
""" """
return self.file_log_level_value 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]: 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. This function will return a list of strings that can be logged to show all the logger configs.

View File

@ -125,8 +125,10 @@ def configure_logger():
_LOGGER = logging.getLogger('automation_log') _LOGGER = logging.getLogger('automation_log')
# create the root folder and make the dirs # create the root folder and make the dirs
log_root_folder = logger_config.get_log_location() _LOGGER.log_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'))
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) os.makedirs(_LOGGER.log_folder, exist_ok=True)
log_file = os.path.join(_LOGGER.get_log_folder(), "full_logs.txt") log_file = os.path.join(_LOGGER.get_log_folder(), "full_logs.txt")