"""Logging utils.""" import uuid from ddex_ingester_common.logging.adapters import DdexIngesterAdapter def get_logger(app_logger, message_id=None, message_thread_id=None, correlation_id=None, execution_name=None): """Get logger with a correlation_id attached. Args: app_logger: ows-logger instance message_id: Additional ID to log message_thread_id: Additional ID to log correlation_id: correlation_id that will be sent along with log record execution_name: State machine execution name Returns: DdexIngesterAdapter: instance of DdexIngesterAdapter with correlation_id and other message ids attached. """ return DdexIngesterAdapter( app_logger, { 'message_id': message_id, 'message_thread_id': message_thread_id, 'correlation_id': correlation_id or uuid.uuid4(), 'execution_name': execution_name } ) def update_logger_with_message_ids(logger, message_id, message_thread_id, execution_name): """Set message ids onto logger instance.""" logger.extra = { **logger.extra, 'message_id': message_id, 'message_thread_id': message_thread_id, 'execution_name': execution_name } def update_logger_correlation_id(logger, correlation_id): """Set logger correlation_id.""" logger.extra = { **logger.extra, 'correlation_id': correlation_id }