def get_logger_for_context(context): """ Create logger for context :param context: :return: the logger object :rtype: logging.Logger """ if is_instance_of(context, 'AutoLoadCommandContext'): log_group = INVENTORY resource_name = context.resource.name elif is_instance_of(context, 'ResourceCommandContext'): log_group = context.reservation.reservation_id if context.reservation else INVENTORY resource_name = context.resource.name elif is_instance_of(context, 'ResourceRemoteCommandContext'): log_group = context.remote_reservation.reservation_id if context.remote_reservation else INVENTORY resource_name = context.remote_endpoints[0].name else: raise Exception('get_logger_for_context', 'Unsupported command context provided {0}'.format(context)) exec_info = get_execution_info(context) qs_logger = get_qs_logger(log_group=log_group, log_category='QS', log_file_prefix=resource_name) log_execution_info(qs_logger, exec_info) return qs_logger
def get_logger_for_driver(context=None, config=None): """ Create QS Logger for command context AutoLoadCommandContext, ResourceCommandContext or ResourceRemoteCommandContext :param context: :param config: :return: """ if hasattr(config, 'HANDLER_CLASS'): handler_class = config.HANDLER_CLASS else: handler_class = None if handler_class and isinstance(handler_class, types.ClassType): logger_name = handler_class.__name__ elif handler_class and isinstance(handler_class, str): logger_name = handler_class else: logger_name = 'QS' if is_instance_of(context, config.AUTOLOAD_COMMAND_CONTEXT): reservation_id = 'Autoload' resource_name = context.resource.name elif is_instance_of(context, config.RESOURCE_COMMAND_CONTEXT): reservation_id = context.reservation.reservation_id resource_name = context.resource.name elif is_instance_of(context, config.RESOURCE_REMOTE_COMMAND_CONTEXT): reservation_id = context.remote_reservation.reservation_id resource_name = context.remote_endpoints[0].name else: raise Exception('get_context_based_logger', 'Unsupported command context provided {0}'.format(context)) exec_info = get_execution_info(context) qs_logger = get_qs_logger(reservation_id, logger_name, resource_name) log_execution_info(qs_logger, exec_info) return qs_logger