本文整理了Java中org.apache.logging.log4j.Marker.getParents()
方法的一些代码示例,展示了Marker.getParents()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marker.getParents()
方法的具体详情如下:
包路径:org.apache.logging.log4j.Marker
类名称:Marker
方法名:getParents
[英]Returns a list of parents of this Marker.
[中]返回此标记的父级列表。
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl
@Override
public Iterator<Marker> iterator() {
final org.apache.logging.log4j.Marker[] log4jParents = this.marker.getParents();
final List<Marker> parents = new ArrayList<>(log4jParents.length);
for (final org.apache.logging.log4j.Marker m : log4jParents) {
parents.add(factory.getMarker(m.getName()));
}
return parents.iterator();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@PerformanceSensitive("allocation")
private static void addParentInfo(final StringBuilder sb, final Marker... parents) {
sb.append("[ ");
boolean first = true;
// noinspection ForLoopReplaceableByForEach
for (int i = 0, parentsLength = parents.length; i < parentsLength; i++) {
final Marker marker = parents[i];
if (!first) {
sb.append(", ");
}
first = false;
sb.append(marker.getName());
final Marker[] p = marker instanceof Log4jMarker ? ((Log4jMarker) marker).parents : marker.getParents();
if (p != null) {
addParentInfo(sb, p);
}
}
sb.append(" ]");
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@PerformanceSensitive({"allocation", "unrolled"})
private static boolean checkParent(final Marker parent, final Marker marker) {
if (parent == marker) {
return true;
}
final Marker[] localParents = parent instanceof Log4jMarker ? ((Log4jMarker) parent).parents : parent
.getParents();
if (localParents != null) {
final int localParentsLength = localParents.length;
if (localParentsLength == 1) {
return checkParent(localParents[0], marker);
}
if (localParentsLength == 2) {
return checkParent(localParents[0], marker) || checkParent(localParents[1], marker);
}
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < localParentsLength; i++) {
final Marker localParent = localParents[i];
if (checkParent(localParent, marker)) {
return true;
}
}
}
return false;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testGetMarker() {
final Marker expected = MarkerManager.getMarker("A");
assertNull(expected.getParents());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testDuplicateParents() {
final Marker parent = MarkerManager.getMarker("PARENT");
final Marker existing = MarkerManager.getMarker("EXISTING");
final Marker test1 = MarkerManager.getMarker("TEST1").setParents(existing);
test1.addParents(parent);
final Marker[] parents = test1.getParents();
test1.addParents(existing);
assertTrue("duplicate add allowed", parents.length == test1.getParents().length);
test1.addParents(existing, MarkerManager.getMarker("EXTRA"));
assertTrue("incorrect add", parents.length + 1 == test1.getParents().length);
assertTrue("TEST1 is not an instance of PARENT", test1.isInstanceOf(parent));
assertTrue("TEST1 is not an instance of EXISTING", test1.isInstanceOf(existing));
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
protected void assertLogEvent(final LogEvent logEvent) {
assertThat(logEvent, is(notNullValue()));
assertThat(logEvent.getInstant().getEpochMillisecond(), equalTo(1493121664118L));
assertThat(logEvent.getThreadName(), equalTo("main"));
assertThat(logEvent.getThreadId(), equalTo(1L));
assertThat(logEvent.getThreadPriority(), equalTo(5));
assertThat(logEvent.getLevel(), equalTo(Level.INFO));
assertThat(logEvent.getLoggerName(), equalTo("HelloWorld"));
assertThat(logEvent.getMarker().getName(), equalTo("child"));
assertThat(logEvent.getMarker().getParents()[0].getName(), equalTo("parent"));
assertThat(logEvent.getMarker().getParents()[0].getParents()[0].getName(),
equalTo("grandparent"));
assertThat(logEvent.getMessage().getFormattedMessage(), equalTo("Hello, world!"));
assertThat(logEvent.getThrown(), is(nullValue()));
assertThat(logEvent.getThrownProxy().getMessage(), equalTo("error message"));
assertThat(logEvent.getThrownProxy().getName(), equalTo("java.lang.RuntimeException"));
assertThat(logEvent.getThrownProxy().getExtendedStackTrace()[0].getClassName(),
equalTo("logtest.Main"));
assertThat(logEvent.getLoggerFqcn(), equalTo("org.apache.logging.log4j.spi.AbstractLogger"));
assertThat(logEvent.getContextStack().asList(), equalTo(Arrays.asList("one", "two")));
assertThat((String) logEvent.getContextData().getValue("foo"), equalTo("FOO"));
assertThat((String) logEvent.getContextData().getValue("bar"), equalTo("BAR"));
assertThat(logEvent.getSource().getClassName(), equalTo("logtest.Main"));
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testGetMarkerWithParents() {
final Marker expected = MarkerManager.getMarker("A");
final Marker p1 = MarkerManager.getMarker("P1");
p1.addParents(MarkerManager.getMarker("PP1"));
final Marker p2 = MarkerManager.getMarker("P2");
expected.addParents(p1);
expected.addParents(p2);
assertEquals(2, expected.getParents().length);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j18-impl
@Override
public Iterator<Marker> iterator() {
final org.apache.logging.log4j.Marker[] log4jParents = this.marker.getParents();
final List<Marker> parents = new ArrayList<>(log4jParents.length);
for (final org.apache.logging.log4j.Marker m : log4jParents) {
parents.add(factory.getMarker(m.getName()));
}
return parents.iterator();
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@PerformanceSensitive("allocation")
private static void addParentInfo(final StringBuilder sb, final Marker... parents) {
sb.append("[ ");
boolean first = true;
// noinspection ForLoopReplaceableByForEach
for (int i = 0, parentsLength = parents.length; i < parentsLength; i++) {
final Marker marker = parents[i];
if (!first) {
sb.append(", ");
}
first = false;
sb.append(marker.getName());
final Marker[] p = marker instanceof Log4jMarker ? ((Log4jMarker) marker).parents : marker.getParents();
if (p != null) {
addParentInfo(sb, p);
}
}
sb.append(" ]");
}
}
代码示例来源:origin: SAP/cf-java-logging-support
private void getMarkersRecursively(Marker marker, ArrayComposer<JSONComposer<String>> ac) throws IOException {
if (marker != null) {
ac.add(marker.getName());
Marker[] parents = marker.getParents();
if (parents != null) {
for (Marker parent: parents) {
getMarkersRecursively(parent, ac);
}
}
}
}
}
代码示例来源:origin: de.huxhorn.lilith/de.huxhorn.lilith.log4j2.converter
private Marker initMarkerRecursive(org.apache.logging.log4j.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);
org.apache.logging.log4j.Marker[] parents = origMarker.getParents();
if(parents != null)
{
for (org.apache.logging.log4j.Marker current : parents)
{
newMarker.add(initMarkerRecursive(current, markers));
}
}
return newMarker;
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@PerformanceSensitive({"allocation", "unrolled"})
private static boolean checkParent(final Marker parent, final Marker marker) {
if (parent == marker) {
return true;
}
final Marker[] localParents = parent instanceof Log4jMarker ? ((Log4jMarker) parent).parents : parent
.getParents();
if (localParents != null) {
final int localParentsLength = localParents.length;
if (localParentsLength == 1) {
return checkParent(localParents[0], marker);
}
if (localParentsLength == 2) {
return checkParent(localParents[0], marker) || checkParent(localParents[1], marker);
}
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < localParentsLength; i++) {
final Marker localParent = localParents[i];
if (checkParent(localParent, marker)) {
return true;
}
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!