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

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

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

Marker.addParents介绍

[英]Adds a Marker as a parent to this Marker.
[中]将标记作为父项添加到此标记。

代码示例

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

/**
 * Retrieves or creates a Marker with the specified parent.
 *
 * @param name The name of the Marker.
 * @param parent The parent Marker.
 * @return The Marker with the specified name.
 * @throws IllegalArgumentException if any argument is {@code null}
 * @deprecated Use the Marker add or set methods to add parent Markers. Will be removed by final GA release.
 */
@Deprecated
public static Marker getMarker(final String name, final Marker parent) {
  return getMarker(name).addParents(parent);
}

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

@Override
public void add(final Marker marker) {
  if (marker == null) {
    throw new IllegalArgumentException();
  }
  final Marker m = factory.getMarker(marker.getName());
  this.marker.addParents(((Log4jMarker)m).getLog4jMarker());
}

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

@Test
  public void testTwoParents() throws IOException {
    final Marker expected = MarkerManager.getMarker("A");
    final Marker parent1 = MarkerManager.getMarker("PARENT_MARKER1");
    final Marker parent2 = MarkerManager.getMarker("PARENT_MARKER2");
    expected.addParents(parent1);
    expected.addParents(parent2);
    final String str = writeValueAsString(expected);
    Assert.assertTrue(str.contains("PARENT_MARKER1"));
    Assert.assertTrue(str.contains("PARENT_MARKER2"));
    final Marker actual = reader.readValue(str);
    Assert.assertEquals(expected, actual);
  }
}

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

@Test
public void testOneParent() throws IOException {
  final Marker expected = MarkerManager.getMarker("A");
  final Marker parent = MarkerManager.getMarker("PARENT_MARKER");
  expected.addParents(parent);
  final String str = writeValueAsString(expected);
  Assert.assertTrue(str.contains("PARENT_MARKER"));
  final Marker actual = reader.readValue(str);
  Assert.assertEquals(expected, actual);
}

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

.setMessage(message)
.setSource(new StackTraceElement("com.bar.Foo", "anotherMethod03", "Foo.java", 9))
.setMarker(MarkerManager.getMarker("AnotherMarker").addParents(
  MarkerManager.getMarker("Parent1").addParents(MarkerManager.getMarker("GrandParent1")),
  MarkerManager.getMarker("Parent2")))
.setThreadId(1L)

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

final Marker gfMarker = MarkerManager.getMarker("GrandFatherMarker");
final Marker gmMarker = MarkerManager.getMarker("GrandMotherMarker");
cMarker.addParents(pMarker1);
cMarker.addParents(pMarker2);
pMarker1.addParents(gmMarker);
pMarker1.addParents(gfMarker);
final Exception sourceHelper = new Exception();
sourceHelper.fillInStackTrace();

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

@Test
public void testAddToExistingParents() {
  final Marker parent = MarkerManager.getMarker("PARENT");
  final Marker existing = MarkerManager.getMarker("EXISTING");
  final Marker test1 = MarkerManager.getMarker("TEST1").setParents(existing);
  test1.addParents(parent);
  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-api

@Test
public void testMarker() {
  final Marker parent = MarkerManager.getMarker("PARENT");
  final Marker test1 = MarkerManager.getMarker("TEST1").setParents(parent);
  final Marker test2 = MarkerManager.getMarker("TEST2").addParents(parent);
  assertTrue("TEST1 is not an instance of PARENT", test1.isInstanceOf(parent));
  assertTrue("TEST2 is not an instance of PARENT", test2.isInstanceOf(parent));
}

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

@Test
public void testMultipleParents() {
  final Marker parent1 = MarkerManager.getMarker("PARENT1");
  final Marker parent2 = MarkerManager.getMarker("PARENT2");
  final Marker test1 = MarkerManager.getMarker("TEST1").setParents(parent1, parent2);
  final Marker test2 = MarkerManager.getMarker("TEST2").addParents(parent1, parent2);
  assertTrue("TEST1 is not an instance of PARENT1", test1.isInstanceOf(parent1));
  assertTrue("TEST1 is not an instance of PARENT2", test1.isInstanceOf(parent2));
  assertTrue("TEST2 is not an instance of PARENT1", test2.isInstanceOf(parent1));
  assertTrue("TEST2 is not an instance of PARENT2", test2.isInstanceOf(parent2));
}

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

/**
 * Retrieves or creates a Marker with the specified parent.
 *
 * @param name The name of the Marker.
 * @param parent The parent Marker.
 * @return The Marker with the specified name.
 * @throws IllegalArgumentException if any argument is {@code null}
 * @deprecated Use the Marker add or set methods to add parent Markers. Will be removed by final GA release.
 */
@Deprecated
public static Marker getMarker(final String name, final Marker parent) {
  return getMarker(name).addParents(parent);
}

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

@Override
public void add(final Marker marker) {
  if (marker == null) {
    throw new IllegalArgumentException();
  }
  final Marker m = factory.getMarker(marker.getName());
  this.marker.addParents(((Log4jMarker)m).getLog4jMarker());
}

代码示例来源: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: 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;
}

相关文章