org.apache.logging.log4j.ThreadContext.trim()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(137)

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

ThreadContext.trim介绍

[英]Trims elements from this diagnostic context. If the current depth is smaller or equal to maxDepth, then no action is taken. If the current depth is larger than newDepth then all elements at maxDepth or higher are discarded.

This method is a convenient alternative to multiple #pop calls. Moreover, it is often the case that at the end of complex call sequences, the depth of the ThreadContext is unpredictable. The trim method circumvents this problem.

For example, the combination

void foo() { 
final int depth = ThreadContext.getDepth(); 
// ... complex sequence of calls 
ThreadContext.trim(depth); 
}

ensures that between the entry and exit of foo the depth of the diagnostic stack is conserved.
[中]从该诊断上下文中删除元素。如果当前深度小于或等于maxDepth,则不采取任何操作。如果当前深度大于newDepth,则会丢弃maxDepth或更高级别的所有元素。
这种方法是多个#pop调用的方便替代方法。此外,在复杂调用序列的末尾,线程上下文的深度往往是不可预测的。trim方法可以避免这个问题。
例如,组合

void foo() { 
final int depth = ThreadContext.getDepth(); 
// ... complex sequence of calls 
ThreadContext.trim(depth); 
}

确保在foo的入口和出口之间保持诊断堆栈的深度。

代码示例

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

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

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

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.jboss.weld.se/weld-se

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.jboss.weld.servlet/weld-servlet-shaded

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

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

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: weld/core

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: weld/core

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.jboss.weld.se/weld-se-shaded

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
  public void setNdcMaxDepth(int maxDepth) {
    ThreadContext.trim(maxDepth);
  }
}

代码示例来源:origin: org.apache.logging.log4j.adapters/log4j-1.2-api

org.apache.logging.log4j.ThreadContext.trim(maxDepth);

代码示例来源:origin: org.apache.logging.log4j/log4j-1.2-api

org.apache.logging.log4j.ThreadContext.trim(maxDepth);

相关文章