/** * Configure the logger's Mapped Diagnostic Context (MDC) properties for the thread making this call. * * @param contextName the name of the context; may not be null * @return the previous MDC context; never null * @throws IllegalArgumentException if {@code contextName} is null */ public LoggingContext.PreviousContext configureLoggingContext(String contextName) { return LoggingContext.forConnector(connectorType, connectorName, contextName); }
/** * 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 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 void temporaryLoggingContext(String contextName, Runnable operation) { LoggingContext.temporarilyForConnector("MySQL", connectorConfig.getLogicalName(), contextName, 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. * * @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(); } }
LoggingContext.forConnector(getClass().getSimpleName(), "", "engine"); engine.run(); });
executor = Executors.newFixedThreadPool(1); executor.execute(() -> { LoggingContext.forConnector(getClass().getSimpleName(), "", "engine"); engine.run(); });
@Before public final void initializeConnectorTestFramework() { LoggingContext.forConnector(getClass().getSimpleName(), "", "test"); keyJsonConverter = new JsonConverter(); valueJsonConverter = new JsonConverter(); keyJsonDeserializer = new JsonDeserializer(); valueJsonDeserializer = new JsonDeserializer(); Configuration converterConfig = Configuration.create().build(); Configuration deserializerConfig = Configuration.create().build(); keyJsonConverter.configure(converterConfig.asMap(), true); valueJsonConverter.configure(converterConfig.asMap(), false); keyJsonDeserializer.configure(deserializerConfig.asMap(), true); valueJsonDeserializer.configure(deserializerConfig.asMap(), false); resetBeforeEachTest(); consumedLines = new ArrayBlockingQueue<>(getMaximumEnqueuedRecordCount()); Testing.Files.delete(OFFSET_STORE_PATH); OFFSET_STORE_PATH.getParent().toFile().mkdirs(); }
@Override public synchronized void start(Configuration config) { final String serverName = config.getString(MySqlConnectorConfig.SERVER_NAME); PreviousContext prevLoggingContext = LoggingContext.forConnector("MySQL", serverName, "task");
PreviousContext preRunContext = LoggingContext.forConnector(getClass().getSimpleName(), "runner", spec.name()); final Configuration environmentConfig = Configuration.copy(spec.environment()).build(); final Configuration connectorConfig = spec.config(); PreviousContext prev = LoggingContext.forConnector(getClass().getSimpleName(), "runner", spec.name()); try { Testing.debug("actual record: " + SchemaUtil.asString(actualRecord));
/** * Configure the logger's Mapped Diagnostic Context (MDC) properties for the thread making this call. * * @param contextName the name of the context; may not be null * @return the previous MDC context; never null * @throws IllegalArgumentException if {@code contextName} is null */ public LoggingContext.PreviousContext configureLoggingContext(String contextName) { return LoggingContext.forConnector(connectorType, connectorName, contextName); }
/** * 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(); } }
executor = Executors.newFixedThreadPool(1); executor.execute(() -> { LoggingContext.forConnector(getClass().getSimpleName(), "", "engine"); engine.run(); });
LoggingContext.forConnector(getClass().getSimpleName(), "", "engine"); engine.run(); });
@Before public final void initializeConnectorTestFramework() { LoggingContext.forConnector(getClass().getSimpleName(), "", "test"); keyJsonConverter = new JsonConverter(); valueJsonConverter = new JsonConverter(); keyJsonDeserializer = new JsonDeserializer(); valueJsonDeserializer = new JsonDeserializer(); Configuration converterConfig = Configuration.create().build(); Configuration deserializerConfig = Configuration.create().build(); keyJsonConverter.configure(converterConfig.asMap(), true); valueJsonConverter.configure(converterConfig.asMap(), false); keyJsonDeserializer.configure(deserializerConfig.asMap(), true); valueJsonDeserializer.configure(deserializerConfig.asMap(), false); resetBeforeEachTest(); consumedLines = new ArrayBlockingQueue<>(getMaximumEnqueuedRecordCount()); Testing.Files.delete(OFFSET_STORE_PATH); OFFSET_STORE_PATH.getParent().toFile().mkdirs(); }
PreviousContext preRunContext = LoggingContext.forConnector(getClass().getSimpleName(), "runner", spec.name()); final Configuration environmentConfig = Configuration.copy(spec.environment()).build(); final Configuration connectorConfig = spec.config(); PreviousContext prev = LoggingContext.forConnector(getClass().getSimpleName(), "runner", spec.name()); try { Testing.debug("actual record: " + SchemaUtil.asString(actualRecord));