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

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

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

Marker.hasReferences介绍

[英]Does this marker have any 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 boolean hasReferences() {
  return marker.hasReferences();
}

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

@Override
public void add(Marker reference) {
  if(reference instanceof LogstashMarker) {
    // limit to one level to make things a bit less complicated
    if(reference.hasReferences()) {
      throw new IllegalArgumentException("Please do not nest markers in more than one level");
    }
    super.add(reference);
  } else {
    throw new IllegalArgumentException("Expected marker instance of " + LogstashMarker.class.getName());
  }
}

代码示例来源: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: 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: 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: 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: 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: 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: 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: 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: javabeanz/owasp-security-logging

public FilterReply decide(ILoggingEvent event) {
  if (!isStarted()) {
    return FilterReply.NEUTRAL;
  }
  // make sure the event has a marker
  Marker eventMarker = event.getMarker();
  if (eventMarker == null) {
    return FilterReply.DENY;
  }
  if (eventMarker.hasReferences()) {
    // check for events with multiple markers
    for (Marker marker : markersToMatch) {
      if (eventMarker.contains(marker)) {
        return acceptAll ? FilterReply.ACCEPT : FilterReply.NEUTRAL;
      }
    }
  } else {
    // handle simple case of an event with a single marker
    if (markersToMatch.contains(eventMarker)) {
      return acceptAll ? FilterReply.ACCEPT : FilterReply.NEUTRAL;
    }
  }
  // no match found for security markers
  return FilterReply.DENY;
}

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

public FilterReply decide(ILoggingEvent event) {
  if (!isStarted()) {
    return FilterReply.NEUTRAL;
  }
  // make sure the event has a marker
  Marker eventMarker = event.getMarker();
  if (eventMarker == null) {
    return FilterReply.NEUTRAL;
  }
  if (eventMarker.hasReferences()) {
    // check for events with multiple markers
    for (Marker marker : markersToMatch) {
      if (eventMarker.contains(marker)) {
        return FilterReply.DENY;
      }
    }
  } else {
    // handle simple case of an event with a single marker
    if (markersToMatch.contains(eventMarker)) {
      return FilterReply.DENY;
    }
  }
  // no classified markers found
  return FilterReply.NEUTRAL;
}

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

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

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

@Override
public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
  // write only mdc data from domains which have no marker within the current event
  
  Marker marker = event.getMarker();
  if(marker == null) {
    writeFullContext(generator);
  } else if(marker instanceof MdcListMarker) {
    // all mdc data already captured
  } else if(!marker.hasReferences()) {
    if(marker instanceof DomainMarker) {
      writeContextForFilteredMarker(generator, marker);
    } else {
      writeFullContext(generator);
    }
  } else {
    writeContextForFilteredMarkerAndReferences(generator, marker);
  }
}

相关文章