org.slf4j.MDC.remove()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中org.slf4j.MDC.remove()方法的一些代码示例,展示了MDC.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MDC.remove()方法的具体详情如下:
包路径:org.slf4j.MDC
类名称:MDC
方法名:remove

MDC.remove介绍

[英]Remove the diagnostic context identified by the key parameter using the underlying system's MDC implementation. The key parameter cannot be null. This method does nothing if there is no previous value associated with key.
[中]使用基础系统的MDC实现删除key参数标识的诊断上下文。key参数不能为空。如果之前没有与key关联的值,则此方法不会执行任何操作。

代码示例

代码示例来源:origin: ch.qos.logback/logback-classic

void clearMDC() {
  MDC.remove(ClassicConstants.REQUEST_REMOTE_HOST_MDC_KEY);
  MDC.remove(ClassicConstants.REQUEST_REQUEST_URI);
  MDC.remove(ClassicConstants.REQUEST_QUERY_STRING);
  // removing possibly inexistent item is OK
  MDC.remove(ClassicConstants.REQUEST_REQUEST_URL);
  MDC.remove(ClassicConstants.REQUEST_METHOD);
  MDC.remove(ClassicConstants.REQUEST_USER_AGENT_MDC_KEY);
  MDC.remove(ClassicConstants.REQUEST_X_FORWARDED_FOR);
}

代码示例来源:origin: redisson/redisson

public void close() {
    MDC.remove(this.key);
  }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
 public void close() {
  MDC.remove(HTTP_REQUEST_ID_MDC_KEY);
 }
}

代码示例来源:origin: SonarSource/sonarqube

public void clearForTask() {
 MDC.remove(MDC_CE_TASK_UUID);
}

代码示例来源:origin: wildfly/wildfly

public void close() {
    MDC.remove(this.key);
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public void onFinish(SpanWrapper spanWrapper, String operationName, long durationNanos) {
  MDC.remove(TRACE_ID);
  MDC.remove(SPAN_ID);
  MDC.remove(APPLICATION);
  MDC.remove(HOST);
  MDC.remove(INSTANCE);
}

代码示例来源:origin: wildfly/wildfly

public void removeMdc(final String key) {
  MDC.remove(key);
}

代码示例来源:origin: org.slf4j/log4j-over-slf4j

public static void remove(String key) {
  org.slf4j.MDC.remove(key);
}

代码示例来源:origin: alibaba/canal

protected void stop() {
  if (!running) {
    return;
  }
  running = false;
  if (thread != null) {
    try {
      thread.join();
    } catch (InterruptedException e) {
      // ignore
    }
  }
  MDC.remove("destination");
}

代码示例来源:origin: alibaba/canal

@Override
public synchronized void stop() {
  if (!running) {
    return;
  }
  super.stop();
  MDC.remove("destination");
}

代码示例来源:origin: wildfly/wildfly

public Object putMdc(final String key, final Object value) {
  try {
    return MDC.get(key);
  } finally {
    if (value == null) {
      MDC.remove(key);
    } else {
      MDC.put(key, String.valueOf(value));
    }
  }
}

代码示例来源:origin: org.slf4j/log4j-over-slf4j

public static void clear() {
  int depth = getDepth();
  for (int i = 0; i < depth; i++) {
    String key = PREFIX + i;
    MDC.remove(key);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

static void replace(String key, @Nullable String value) {
  if (value != null) {
    MDC.put(key, value);
  }
  else {
    MDC.remove(key);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

static void replace(String key, @Nullable String value) {
  if (value != null) {
    MDC.put(key, value);
  }
  else {
    MDC.remove(key);
  }
}

代码示例来源:origin: apache/activemq

public static void stopped(String host) {
  SERVERS.remove(host);
  TransportConnector connector = CONNECTORS.remove(host);
  if (connector != null) {
    LOG.debug("Shutting down VM connectors for broker: " + host);
    ServiceSupport.dispose(connector);
    BrokerService broker = BROKERS.remove(host);
    if (broker != null) {
      ServiceSupport.dispose(broker);
    }
    MDC.remove("activemq.broker");
  }
}

代码示例来源:origin: alibaba/canal

public void stop() {
  super.stop();
  for (Map.Entry<String, CanalInstance> entry : canalInstances.entrySet()) {
    try {
      CanalInstance instance = entry.getValue();
      if (instance.isStart()) {
        try {
          String destination = entry.getKey();
          MDC.put("destination", destination);
          entry.getValue().stop();
          logger.info("stop CanalInstances[{}] successfully", destination);
        } finally {
          MDC.remove("destination");
        }
      }
    } catch (Exception e) {
      logger.error(String.format("stop CanalInstance[%s] has an error", entry.getKey()), e);
    }
  }
  metrics.terminate();
}

代码示例来源:origin: alibaba/canal

public void start(final String destination) {
  final CanalInstance canalInstance = canalInstances.get(destination);
  if (!canalInstance.isStart()) {
    try {
      MDC.put("destination", destination);
      if (metrics.isRunning()) {
        metrics.register(canalInstance);
      }
      canalInstance.start();
      logger.info("start CanalInstances[{}] successfully", destination);
    } finally {
      MDC.remove("destination");
    }
  }
}

代码示例来源:origin: alibaba/yugong

private void processException(Table table, Exception e) {
  MDC.remove(YuGongConstants.MDC_TABLE_SHIT_KEY);
  abort("process table[" + table.getFullName() + "] has error!", e);
  System.exit(-1);// 串行时,出错了直接退出jvm
}

代码示例来源:origin: alibaba/canal

public void stop(String destination) {
  CanalInstance canalInstance = canalInstances.remove(destination);
  if (canalInstance != null) {
    if (canalInstance.isStart()) {
      try {
        MDC.put("destination", destination);
        canalInstance.stop();
        if (metrics.isRunning()) {
          metrics.unregister(canalInstance);
        }
        logger.info("stop CanalInstances[{}] successfully", destination);
      } finally {
        MDC.remove("destination");
      }
    }
  }
}

代码示例来源:origin: org.slf4j/log4j-over-slf4j

public static String pop() {
  int next = getDepth();
  if (next == 0) {
    return "";
  }
  int last = next - 1;
  String key = PREFIX + last;
  String val = MDC.get(key);
  MDC.remove(key);
  return val;
}

相关文章