org.slf4j.Marker.iterator()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(150)

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

Marker.iterator介绍

[英]Returns an Iterator which can be used to iterate over the references of this marker. An empty iterator is returned when this marker has no references.
[中]返回一个迭代器,该迭代器可用于迭代此标记的引用。当这个标记没有引用时,返回一个空迭代器。

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl

private static org.apache.logging.log4j.Marker convertMarker(final Marker original,
                               final Collection<Marker> visited) {
  final org.apache.logging.log4j.Marker marker = MarkerManager.getMarker(original.getName());
  if (original.hasReferences()) {
    final Iterator<Marker> it = original.iterator();
    while (it.hasNext()) {
      final Marker next = it.next();
      if (visited.contains(next)) {
        LOGGER.warn("Found a cycle in Marker [{}]. Cycle will be broken.", next.getName());
      } else {
        visited.add(next);
        marker.addParents(convertMarker(next, visited));
      }
    }
  }
  return marker;
}

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

@Override
public Iterator<Marker> iterator() {
  return marker.iterator();
}

代码示例来源:origin: com.lightstreamer/cloudwatch-logback-appender

private static Set<String> getMarkers(final ILoggingEvent eventObject) {
  final Marker marker = eventObject.getMarker();
  if (marker == null) {
    return null;
  }
  final Set<String> markers = new TreeSet<>();
  Iterator<?> i = marker.iterator();
  while (i.hasNext()) {
    markers.add(i.next().toString());
  }
  return markers;
}

代码示例来源:origin: dCache/dcache

private static Marker getSubmarker(Marker marker, String name) {
    Preconditions.checkNotNull(marker);
    Preconditions.checkNotNull(name);
    for (Iterator<Marker> m = marker.iterator(); m.hasNext();) {
      Marker next = m.next();
      if (name.equals(next.getName())) {
        return next;
      }
    }
    return null;
  }
}

代码示例来源:origin: dev.rico/rico-logger

private List<String> convert(final Marker marker) {
  Objects.requireNonNull(marker);
  List<String> ret = new ArrayList<>();
  ret.add(marker.getName());
  Iterator<Marker> children = marker.iterator();
  while (children.hasNext()) {
    ret.addAll(convert(children.next()));
  }
  return ret;
}

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

public static String getMarkerName(Marker marker)
{
  StringBuffer sb = new StringBuffer();
  sb.append(marker.getName());
  if (marker.hasReferences()) {
    // follow only first reference. Multiple references will be ignored.
    Marker reference = (Marker) marker.iterator().next();
    sb.append(".");
    sb.append(getMarkerName(reference));
  }
  return sb.toString();
}

代码示例来源:origin: SAP/cf-java-logging-support

private void getMarkersRecursively(Marker marker, ArrayComposer<JSONComposer<String>> ac) throws IOException {
  if (marker != null) {
    ac.add(marker.getName());
    Iterator<Marker> it = marker.iterator();
    while (it.hasNext()) {
      getMarkersRecursively(it.next(), ac);
    }
  }
}

代码示例来源:origin: com.sap.cloud.yaas.service-sdk/service-sdk-logging

private List<String> resolveMarkerNames(final Marker marker)
  {
    if (marker != null)
    {
      final List<String> result = new ArrayList<String>();
      result.add(marker.getName());
      if (marker.hasReferences())
      {
        for (final Iterator<Marker> iter = marker.iterator(); iter.hasNext();)
        {
          final Marker next = iter.next();
          result.addAll(resolveMarkerNames(next));
        }
      }
      return result;
    }
    return Collections.emptyList();
  }
}

代码示例来源:origin: net.logstash.logback/logstash-logback-encoder

private void writeLogstashMarkerIfNecessary(JsonGenerator generator, Marker marker) throws IOException {
  if (marker != null) {
    if (isLogstashMarker(marker)) {
      ((LogstashMarker) marker).writeTo(generator);
    }
    
    if (marker.hasReferences()) {
      for (Iterator<?> i = marker.iterator(); i.hasNext();) {
        Marker next = (Marker) i.next();
        writeLogstashMarkerIfNecessary(generator, next);
      }
    }
  }
}

代码示例来源:origin: com.github.skjolber.log-domain/log-domain-support-logback

private void writeContextForFilteredMarkerAndReferences(JsonGenerator generator, Marker marker) throws IOException {
  // filter MDCs for the current marker plus all its references
  @SuppressWarnings("rawtypes")
  Set<Class> filter = new HashSet<>();
  if(marker instanceof DomainMarker) {
    filter.add(marker.getClass());
  }
    
  Iterator<Marker> iterator = marker.iterator();
  while(iterator.hasNext()) {
    Marker next = iterator.next();
    
    if(next instanceof DomainMarker) {
      filter.add(next.getClass());
    }
  }
  
  // write mdc context now
  for (DomainMdc<? extends DomainMarker> mdc : DomainMdc.getMdcs()) { // list of possible MDCs
    if(filter.contains(mdc.getType())) {
      // skip
      continue;
    }
    DomainMarker mdcMarker = mdc.get();
    if(mdcMarker != null) {
      mdcMarker.writeTo(generator);
    }
  }
}

代码示例来源:origin: zolyfarkas/spf4j

static void printMarker(final Marker marker, final Appendable wr,
   final EscapeJsonStringAppendableWrapper wrapper)
   throws IOException {
 if (marker.hasReferences()) {
  wr.append('{');
  wr.append('"');
  wrapper.append(marker.getName());
  wr.append("\":[");
  Iterator<Marker> it = marker.iterator();
  if (it.hasNext()) {
   printMarker(it.next(), wr, wrapper);
   while (it.hasNext()) {
    wr.append(',');
    printMarker(it.next(), wr, wrapper);
   }
  }
  wr.append("]}");
 } else {
  wr.append('"');
  wrapper.append(marker.getName());
  wr.append('"');
 }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j18-impl

private static org.apache.logging.log4j.Marker convertMarker(final Marker original,
                               final Collection<Marker> visited) {
  final org.apache.logging.log4j.Marker marker = MarkerManager.getMarker(original.getName());
  if (original.hasReferences()) {
    final Iterator<Marker> it = original.iterator();
    while (it.hasNext()) {
      final Marker next = it.next();
      if (visited.contains(next)) {
        LOGGER.warn("Found a cycle in Marker [{}]. Cycle will be broken.", next.getName());
      } else {
        visited.add(next);
        marker.addParents(convertMarker(next, visited));
      }
    }
  }
  return marker;
}

代码示例来源:origin: javabeanz/owasp-security-logging

public static Marker convertMarker(org.slf4j.Marker input) {
  Marker output = MarkerManager.getMarker(input.getName());
  
  if (input.hasReferences()) {
    Iterator i = input.iterator();
    while (i.hasNext()) {
      org.slf4j.Marker ref = (org.slf4j.Marker)i.next();
      output.addParents(convertMarker(ref));
    }
  }
  return output;
}

代码示例来源:origin: net.logstash.logback/logstash-logback-encoder

@SuppressWarnings("deprecation")
private boolean writeTagIfNecessary(JsonGenerator generator, boolean hasWrittenStart, final Marker marker) throws IOException {
  if (!marker.getName().equals(JsonMessageJsonProvider.JSON_MARKER_NAME)
      && !LogstashMarkersJsonProvider.isLogstashMarker(marker)) {
    if (!hasWrittenStart) {
      generator.writeArrayFieldStart(getFieldName());
      hasWrittenStart = true;
    }
    generator.writeString(marker.getName());
  }
  if (marker.hasReferences()) {
    
    for (Iterator<?> i = marker.iterator(); i.hasNext();) {
      Marker next = (Marker) i.next();
      
      hasWrittenStart |= writeTagIfNecessary(generator, hasWrittenStart, next);
    }
  }
  return hasWrittenStart;
}

代码示例来源:origin: de.huxhorn.lilith/de.huxhorn.lilith.logback.converter-classic

private Marker initMarkerRecursive(org.slf4j.Marker origMarker, Map<String, Marker> markers)
{
  if(origMarker == null)
  {
    return null;
  }
  String name = origMarker.getName();
  if(markers.containsKey(name))
  {
    return markers.get(name);
  }
  Marker newMarker = new Marker(name);
  markers.put(name, newMarker);
  if(origMarker.hasReferences())
  {
    Iterator iter = origMarker.iterator();
    while(iter.hasNext())
    {
      org.slf4j.Marker current = (org.slf4j.Marker) iter.next();
      newMarker.add(initMarkerRecursive(current, markers));
    }
  }
  return newMarker;
}

代码示例来源:origin: de.huxhorn.lilith/de.huxhorn.lilith.logback.logging-adapter

private Marker initMarkerRecursive(org.slf4j.Marker origMarker, Map<String, Marker> markers)
  {
    if(origMarker == null)
    {
      return null;
    }
    String name = origMarker.getName();
    if(markers.containsKey(name))
    {
      return markers.get(name);
    }
    Marker newMarker = new Marker(name);
    markers.put(name, newMarker);
    if(origMarker.hasReferences())
    {
      Iterator iter = origMarker.iterator();
      while(iter.hasNext())
      {
        org.slf4j.Marker current = (org.slf4j.Marker) iter.next();
        newMarker.add(initMarkerRecursive(current, markers));
      }
    }
    return newMarker;
  }
}

代码示例来源:origin: com.github.skjolber.log-domain/log-domain-support-logback

Iterator<Marker> iterator = marker.iterator();
while(iterator.hasNext()) {
  Marker next = iterator.next();

代码示例来源:origin: co.wrisk.logback/logback-ext-jackson

protected void writeMarker(JsonWriter.ObjectWriter<JsonWriter> writer, ILoggingEvent event) throws IOException {
  Marker marker = event.getMarker();
  if (marker != null) {
    JsonWriter.ArrayWriter<JsonWriter.ObjectWriter<JsonWriter.ObjectWriter<JsonWriter>>> aw =
        writer.writeObject(fieldNames.getMarker(), isActive(fieldNames.getMarker())).writeArray(marker.getName(), true);
    Iterator<Marker> markers = marker.iterator();
    while (markers.hasNext()) {
      String name = markers.next().getName();
      aw.writeString(name, name != null && !name.isEmpty());
    }
    aw.done().done();
  }
}

代码示例来源:origin: io.redlink.ext.logback/logback-ext-jackson

protected void writeMarker(JsonWriter.ObjectWriter<JsonWriter> writer, ILoggingEvent event) throws IOException {
  Marker marker = event.getMarker();
  if (marker != null) {
    JsonWriter.ArrayWriter<JsonWriter.ObjectWriter<JsonWriter.ObjectWriter<JsonWriter>>> aw =
        writer.writeObject(fieldNames.getMarker(), isActive(fieldNames.getMarker())).writeArray(marker.getName(), true);
    Iterator<Marker> markers = marker.iterator();
    while (markers.hasNext()) {
      String name = markers.next().getName();
      aw.writeString(name, name != null && !name.isEmpty());
    }
    aw.done().done();
  }
}

相关文章