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

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

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

Marker.setParents介绍

[英]Replaces the set of parent Markers with the provided Markers.
[中]用提供的标记替换父标记集。

代码示例

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

final Marker testParent = MarkerManager.getMarker("testParent").setParents(testGrandParent);
final Marker test = MarkerManager.getMarker("test").setParents(testParent); // initial creation, value is cached

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

@Test
  public void testLookup() {
    final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
    final Marker eventMarker = MarkerManager.getMarker("EVENT");
    final Marker auditMarker = MarkerManager.getMarker("AUDIT").setParents(eventMarker);
    final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setMarker(auditMarker)
        .setLevel(Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    final MarkerPatternConverter converter = MarkerPatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(auditMarker.toString(), sb.toString());
  }
}

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

@Test
public void testHasParents() {
  final Marker parent = MarkerManager.getMarker("PARENT");
  final Marker existing = MarkerManager.getMarker("EXISTING");
  assertFalse(existing.hasParents());
  existing.setParents(parent);
  assertTrue(existing.hasParents());
}

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

@Test
  public void testLookup() {
    final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
    final Marker eventMarker = MarkerManager.getMarker("EVENT");
    final Marker auditMarker = MarkerManager.getMarker("AUDIT").setParents(eventMarker);
    final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setMarker(auditMarker)
        .setLevel(Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    final MarkerSimpleNamePatternConverter converter = MarkerSimpleNamePatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(auditMarker.getName(), sb.toString());
  }
}

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

@Test
  public void testMarkers() {
    final Marker parent = MarkerManager.getMarker("Parent");
    final Marker child = MarkerManager.getMarker("Child").setParents(parent);
    final Marker grandChild = MarkerManager.getMarker("GrandChild").setParents(child);
    final Marker sibling = MarkerManager.getMarker("Sibling").setParents(parent);
    final Marker stranger = MarkerManager.getMarker("Stranger");
    MarkerFilter filter = MarkerFilter.createFilter("Parent", null, null);
    filter.start();
    assertTrue(filter.isStarted());
    assertSame(Filter.Result.DENY, filter.filter(null, null, stranger, (Object) null, (Throwable) null));
    assertSame(Filter.Result.NEUTRAL, filter.filter(null, null, child, (Object) null, (Throwable) null));
    assertSame(Filter.Result.NEUTRAL, filter.filter(null, null, grandChild, (Object) null, (Throwable) null));
    filter.stop();
    LogEvent event = Log4jLogEvent.newBuilder() //
        .setMarker(grandChild) //
        .setLevel(Level.DEBUG) //
        .setMessage(new SimpleMessage("Hello, world!")).build();
    assertSame(Filter.Result.NEUTRAL, filter.filter(event));
    filter = MarkerFilter.createFilter("Child", null, null);
    filter.start();
    assertSame(Filter.Result.NEUTRAL, filter.filter(event));
    event = Log4jLogEvent.newBuilder() //
        .setMarker(sibling) //
        .setLevel(Level.DEBUG) //
        .setMessage(new SimpleMessage("Hello, world!")).build();
    assertSame(Filter.Result.DENY, filter.filter(event));
    filter.stop();
  }
}

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

相关文章