Class LoggingContext


  • public class LoggingContext
    extends Object
    A utility that provides a consistent set of properties for the Mapped Diagnostic Context (MDC) properties used by Debezium components.
    Since:
    0.2
    Author:
    Randall Hauch
    • Field Detail

      • CONNECTOR_TYPE

        public static final String CONNECTOR_TYPE
        The key for the connector type MDC property.
        See Also:
        Constant Field Values
      • CONNECTOR_NAME

        public static final String CONNECTOR_NAME
        The key for the connector logical name MDC property.
        See Also:
        Constant Field Values
      • CONNECTOR_CONTEXT

        public static final String CONNECTOR_CONTEXT
        The key for the connector context name MDC property.
        See Also:
        Constant Field Values
    • Constructor Detail

      • LoggingContext

        private LoggingContext()
    • Method Detail

      • forConnector

        public static LoggingContext.PreviousContext forConnector​(String connectorType,
                                                                  String connectorName,
                                                                  String contextName)
        Configure for a connector the logger's Mapped Diagnostic Context (MDC) properties for the thread making this call.
        Parameters:
        connectorType - the type of connector; may not be null
        connectorName - the name of the connector; may not be null
        contextName - the name of the context; may not be null
        Returns:
        the previous MDC context; never null
        Throws:
        IllegalArgumentException - if any of the parameters are null
      • temporarilyForConnector

        public static void temporarilyForConnector​(String connectorType,
                                                   String connectorName,
                                                   String contextName,
                                                   Runnable operation)
        Run the supplied function in the temporary connector MDC context, and when complete always return the MDC context to its state before this method was called.
        Parameters:
        connectorType - the type of connector; may not be null
        connectorName - the logical name of the connector; may not be null
        contextName - the name of the context; may not be null
        operation - the function to run in the new MDC context; may not be null
        Throws:
        IllegalArgumentException - if any of the parameters are null