gameboy_worlds.utils.log_handling
1from gameboy_worlds.utils.fundamental import meta_dict_to_str 2from gameboy_worlds.utils.parameter_handling import load_parameters 3import sys 4 5 6def log_error(message: str, parameters: dict = None): 7 """ 8 Log an error message and raise a ValueError. 9 Args: 10 message (str): The error message to log. 11 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 12 If parameters is None, the default parameters will be loaded from the config files 13 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 14 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 15 """ 16 parameters = load_parameters(parameters) 17 logger = parameters["logger"] 18 logger.error(message, stacklevel=2) 19 raise RuntimeError() 20 # sys.exit(1) 21 22 23def log_warn(message: str, parameters: dict = None): 24 """ 25 Log a warning message. 26 Args: 27 message (str): The warning message to log. 28 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 29 If parameters is None, the default parameters will be loaded from the config files 30 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 31 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 32 """ 33 parameters = load_parameters(parameters) 34 logger = parameters["logger"] 35 logger.warn(message, stacklevel=2) 36 37 38def log_info(message: str, parameters: dict = None): 39 """ 40 Log an info message. 41 Args: 42 message (str): The info message to log. 43 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 44 If parameters is None, the default parameters will be loaded from the config files 45 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 46 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 47 """ 48 parameters = load_parameters(parameters) 49 logger = parameters["logger"] 50 logger.info(message, stacklevel=2) 51 52 53def log_dict(meta_dict: dict, *, parameters: dict = None, n_indents: int = 1): 54 """ 55 Print a dictionary in a readable format 56 Args: 57 meta_dict (dict): The dictionary to log. 58 n_indents (int, optional): Number of indentation levels for formatting. Defaults to 1. 59 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 60 If parameters is None, the default parameters will be loaded from the config files 61 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 62 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 63 """ 64 parameters = load_parameters(parameters) 65 logger = parameters["logger"] 66 meta_dict_str = meta_dict_to_str( 67 meta_dict, print_mode=True, n_indents=n_indents, skip_write_timestamp=False 68 ) 69 logger.info("\n" + meta_dict_str, stacklevel=2)
def
log_error(message: str, parameters: dict = None):
7def log_error(message: str, parameters: dict = None): 8 """ 9 Log an error message and raise a ValueError. 10 Args: 11 message (str): The error message to log. 12 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 13 If parameters is None, the default parameters will be loaded from the config files 14 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 15 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 16 """ 17 parameters = load_parameters(parameters) 18 logger = parameters["logger"] 19 logger.error(message, stacklevel=2) 20 raise RuntimeError() 21 # sys.exit(1)
Log an error message and raise a ValueError.
Arguments:
- message (str): The error message to log.
- parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details.
- If parameters is None, the default parameters will be loaded from the config files
- If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None
- will not log to the command line file. In general, use None only if you are confident that the parameters have not been changed.
def
log_warn(message: str, parameters: dict = None):
24def log_warn(message: str, parameters: dict = None): 25 """ 26 Log a warning message. 27 Args: 28 message (str): The warning message to log. 29 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 30 If parameters is None, the default parameters will be loaded from the config files 31 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 32 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 33 """ 34 parameters = load_parameters(parameters) 35 logger = parameters["logger"] 36 logger.warn(message, stacklevel=2)
Log a warning message.
Arguments:
- message (str): The warning message to log.
- parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details.
- If parameters is None, the default parameters will be loaded from the config files
- If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None
- will not log to the command line file. In general, use None only if you are confident that the parameters have not been changed.
def
log_info(message: str, parameters: dict = None):
39def log_info(message: str, parameters: dict = None): 40 """ 41 Log an info message. 42 Args: 43 message (str): The info message to log. 44 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 45 If parameters is None, the default parameters will be loaded from the config files 46 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 47 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 48 """ 49 parameters = load_parameters(parameters) 50 logger = parameters["logger"] 51 logger.info(message, stacklevel=2)
Log an info message.
Arguments:
- message (str): The info message to log.
- parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details.
- If parameters is None, the default parameters will be loaded from the config files
- If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None
- will not log to the command line file. In general, use None only if you are confident that the parameters have not been changed.
def
log_dict(meta_dict: dict, *, parameters: dict = None, n_indents: int = 1):
54def log_dict(meta_dict: dict, *, parameters: dict = None, n_indents: int = 1): 55 """ 56 Print a dictionary in a readable format 57 Args: 58 meta_dict (dict): The dictionary to log. 59 n_indents (int, optional): Number of indentation levels for formatting. Defaults to 1. 60 parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details. 61 If parameters is None, the default parameters will be loaded from the config files 62 If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None 63 will *not* log to the command line file. In general, use None only if you are confident that the parameters have not been changed. 64 """ 65 parameters = load_parameters(parameters) 66 logger = parameters["logger"] 67 meta_dict_str = meta_dict_to_str( 68 meta_dict, print_mode=True, n_indents=n_indents, skip_write_timestamp=False 69 ) 70 logger.info("\n" + meta_dict_str, stacklevel=2)
Print a dictionary in a readable format
Arguments:
- meta_dict (dict): The dictionary to log.
- n_indents (int, optional): Number of indentation levels for formatting. Defaults to 1.
- parameters (dict, optional): Parameters dictionary containing the logger. See load_parameters for details.
- If parameters is None, the default parameters will be loaded from the config files
- If the log_file or log_dir is overwritten in the command line parameters, then calling this function with parameters=None
- will not log to the command line file. In general, use None only if you are confident that the parameters have not been changed.