/** * Configure for a connector the logger's Mapped Diagnostic Context (MDC) properties for the thread making this call. * * @param connectorType the type of connector; may not be null * @param connectorName the name of the connector; may not be null * @param contextName the name of the context; may not be null * @return the previous MDC context; never null * @throws IllegalArgumentException if any of the parameters are null */ public static PreviousContext forConnector(String connectorType, String connectorName, String contextName) { if (connectorType == null) throw new IllegalArgumentException("The MDC value for the connector type may not be null"); if (connectorName == null) throw new IllegalArgumentException("The MDC value for the connector name may not be null"); if (contextName == null) throw new IllegalArgumentException("The MDC value for the connector context may not be null"); PreviousContext previous = new PreviousContext(); MDC.put(CONNECTOR_TYPE, connectorType); MDC.put(CONNECTOR_NAME, connectorName); MDC.put(CONNECTOR_CONTEXT, contextName); return previous; }
/** * 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. * * @param connectorType the type of connector; may not be null * @param connectorName the logical name of the connector; may not be null * @param contextName the name of the context; may not be null * @param operation the function to run in the new MDC context; may not be null * @throws IllegalArgumentException if any of the parameters are null */ public static void temporarilyForConnector(String connectorType, String connectorName, String contextName, Runnable operation) { if (connectorType == null) throw new IllegalArgumentException("The MDC value for the connector type may not be null"); if (connectorName == null) throw new IllegalArgumentException("The MDC value for the connector name may not be null"); if (contextName == null) throw new IllegalArgumentException("The MDC value for the connector context may not be null"); if (operation == null) throw new IllegalArgumentException("The operation may not be null"); PreviousContext previous = new PreviousContext(); try { forConnector(connectorType, connectorName, contextName); operation.run(); } finally { previous.restore(); } }
/** * Configure for a connector the logger's Mapped Diagnostic Context (MDC) properties for the thread making this call. * * @param connectorType the type of connector; may not be null * @param connectorName the name of the connector; may not be null * @param contextName the name of the context; may not be null * @return the previous MDC context; never null * @throws IllegalArgumentException if any of the parameters are null */ public static PreviousContext forConnector(String connectorType, String connectorName, String contextName) { if (connectorType == null) throw new IllegalArgumentException("The MDC value for the connector type may not be null"); if (connectorName == null) throw new IllegalArgumentException("The MDC value for the connector name may not be null"); if (contextName == null) throw new IllegalArgumentException("The MDC value for the connector context may not be null"); PreviousContext previous = new PreviousContext(); MDC.put(CONNECTOR_TYPE, connectorType); MDC.put(CONNECTOR_NAME, connectorName); MDC.put(CONNECTOR_CONTEXT, contextName); return previous; }
/** * 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. * * @param connectorType the type of connector; may not be null * @param connectorName the logical name of the connector; may not be null * @param contextName the name of the context; may not be null * @param operation the function to run in the new MDC context; may not be null * @throws IllegalArgumentException if any of the parameters are null */ public static void temporarilyForConnector(String connectorType, String connectorName, String contextName, Runnable operation) { if (connectorType == null) throw new IllegalArgumentException("The MDC value for the connector type may not be null"); if (connectorName == null) throw new IllegalArgumentException("The MDC value for the connector name may not be null"); if (contextName == null) throw new IllegalArgumentException("The MDC value for the connector context may not be null"); if (operation == null) throw new IllegalArgumentException("The operation may not be null"); PreviousContext previous = new PreviousContext(); try { forConnector(connectorType, connectorName, contextName); operation.run(); } finally { previous.restore(); } }