org.slf4j.Marker类的使用及代码示例

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

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

Marker介绍

[英]Markers are named objects used to enrich log statements. Conforming logging system Implementations of SLF4J determine how information conveyed by markers are used, if at all. In particular, many conforming logging systems ignore marker data.

Markers can contain references to other markers, which in turn may contain references of their own.
[中]标记是用于充实日志语句的命名对象。SLF4J的一致性记录系统实现决定了如何使用标记传递的信息(如果有的话)。特别是,许多符合要求的测井系统忽略了标记数据。
标记可以包含对其他标记的引用,而其他标记又可以包含自己的引用。

代码示例

代码示例来源: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: redisson/redisson

public void add(Marker reference) {
  if (reference == null) {
    throw new IllegalArgumentException("A null value cannot be added to a Marker as reference.");
  }
  // no point in adding the reference multiple times
  if (this.contains(reference)) {
    return;
  } else if (reference.contains(this)) { // avoid recursion
    // a potential reference should not hold its future "parent" as a reference
    return;
  } else {
    referenceList.add(reference);
  }
}

代码示例来源:origin: stackoverflow.com

public class MarkerDemoActivity extends android.support.v4.app.FragmentActivity
  implements OnMarkerClickListener
{
  private Marker myMarker;    

  private void setUpMap()
  {
    .......
    googleMap.setOnMarkerClickListener(this);

    myMarker = googleMap.addMarker(new MarkerOptions()
          .position(latLng)
          .title("My Spot")
          .snippet("This is my spot!")
          .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    ......
  }

  @Override
  public boolean onMarkerClick(final Marker marker) {

    if (marker.equals(myMarker)) 
    {
      //handle click here
    }
  }
}

代码示例来源:origin: stackoverflow.com

// Since we are consuming the event this is necessary to
// manage closing opened markers before opening new ones
Marker lastOpened = null;

mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
  public boolean onMarkerClick(Marker marker) {
    // Check if there is an open info window
    if (lastOpened != null) {
      // Close the info window
      lastOpened.hideInfoWindow();

      // Is the marker the same marker that was already open
      if (lastOpened.equals(marker)) {
        // Nullify the lastOpened object
        lastOpened = null;
        // Return so that the info window isn't opened again
        return true;
      } 
    }

    // Open the info window for the marker
    marker.showInfoWindow();
    // Re-assign the last opened such that we can close it later
    lastOpened = marker;

    // Event was handled by our code do not launch default behaviour.
    return true;
  }
});

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

public boolean equals(Object obj) {
  if (this == obj)
    return true;
  if (obj == null)
    return false;
  if (!(obj instanceof Marker))
    return false;
  final Marker other = (Marker) obj;
  return name.equals(other.getName());
}

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

public String toString() {
    if (!this.hasReferences()) {
      return this.getName();
    }
    Iterator<Marker> it = this.iterator();
    Marker reference;
    StringBuilder sb = new StringBuilder(this.getName());
    sb.append(' ').append(OPEN);
    while (it.hasNext()) {
      reference = it.next();
      sb.append(reference.getName());
      if (it.hasNext()) {
        sb.append(SEP);
      }
    }
    sb.append(CLOSE);

    return sb.toString();
  }
}

代码示例来源: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: redisson/redisson

public boolean contains(Marker other) {
  if (other == null) {
    throw new IllegalArgumentException("Other cannot be null");
  }
  if (this.equals(other)) {
    return true;
  }
  if (hasReferences()) {
    for (Marker ref : referenceList) {
      if (ref.contains(other)) {
        return true;
      }
    }
  }
  return false;
}

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

static public boolean match(Marker marker, Marker[] markerArray) {
  if (markerArray == null) {
    throw new IllegalArgumentException("markerArray should not be null");
  }
  // System.out.println("event marker="+marker);
  final int size = markerArray.length;
  for (int i = 0; i < size; i++) {
    // System.out.println("other:"+markerArray[i]);
    if (marker.contains(markerArray[i])) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: naver/ngrinder

@Override
public void setCurrentRunNumber(int run) {
  if (m_runMarker != null) {
    m_threadMarker.remove(m_runMarker);
    MarkerFactory.getIMarkerFactory().detachMarker(
        m_runMarker.getName());
  }
  if (run != -1) {
    m_runMarker = MarkerFactory.getMarker("run-" + run);
    m_threadMarker.add(m_runMarker);
  }
  m_runNumber = run;
}

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

/**
 * This method is mainly used with Expression Evaluators.
 */
public boolean contains(String name) {
  if (name == null) {
    throw new IllegalArgumentException("Other cannot be null");
  }
  if (this.name.equals(name)) {
    return true;
  }
  if (hasReferences()) {
    for (Marker ref : referenceList) {
      if (ref.contains(name)) {
        return true;
      }
    }
  }
  return false;
}

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

@Test
public void testAddSameMarker() {
  final String childMarkerName = CHILD_MAKER_NAME + "-ASM";
  final String parentMakerName = PARENT_MARKER_NAME + "-ASM";
  final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName);
  final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName);
  slf4jMarker.add(slf4jParent);
  slf4jMarker.add(slf4jParent);
  final Marker log4jParent = MarkerManager.getMarker(parentMakerName);
  final Marker log4jMarker = MarkerManager.getMarker(childMarkerName);
  assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j",
      childMarkerName, parentMakerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent));
  assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J",
      childMarkerName, parentMakerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent));
}

代码示例来源: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: org.apache.logging.log4j/log4j-slf4j-impl

@Test
public void testAddNullMarker() {
  final String childMarkerName = CHILD_MAKER_NAME + "-ANM";
  final String parentMakerName = PARENT_MARKER_NAME + "-ANM";
  final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName);
  final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName);
  slf4jMarker.add(slf4jParent);
  final Marker log4jParent = MarkerManager.getMarker(parentMakerName);
  final Marker log4jMarker = MarkerManager.getMarker(childMarkerName);
  final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent);
  final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker);
  final org.slf4j.Marker nullMarker = null;
  try {
    log4jSlf4jParent.add(nullMarker);
    fail("Expected " + IllegalArgumentException.class.getName());
  } catch (final IllegalArgumentException e) {
    // expected
  }
  try {
    log4jSlf4jMarker.add(nullMarker);
    fail("Expected " + IllegalArgumentException.class.getName());
  } catch (final IllegalArgumentException e) {
    // expected
  }
}

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

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

代码示例来源: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: naver/ngrinder

/** Package scope for unit tests. */
void setTestLogMarker(Marker marker) {
  if (m_testMarker != null) {
    m_threadMarker.remove(m_testMarker);
  }
  m_testMarker = marker;
  if (marker != null) {
    m_threadMarker.add(marker);
  }
}

代码示例来源:origin: stackoverflow.com

return mMarker.hashCode();
if(o instanceof PicassoMarker) {
  Marker marker = ((PicassoMarker) o).mMarker;
  return mMarker.equals(marker);
} else {
  return false;
mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));

代码示例来源:origin: stackoverflow.com

@Override
public boolean onMarkerClick(final Marker marker) {
  if (marker.equals(myMarker)) {
    //handle click here
    marker.remove();
  }
}

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

@Override
public boolean hasReferences() {
  return marker.hasReferences();
}

相关文章