本文整理了Java中org.apache.logging.log4j.Marker
类的一些代码示例,展示了Marker
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marker
类的具体详情如下:
包路径:org.apache.logging.log4j.Marker
类名称:Marker
[英]Markers are objects that are used to add easily filterable information to log messages. Markers can be hierarchical - each Marker may have a parent. This allows for broad categories being subdivided into more specific categories. An example might be a Marker named "Error" with children named "SystemError" and "ApplicationError".
[中]标记是用于向日志消息添加易于过滤的信息的对象。标记可以是分层的——每个标记可能有一个父标记。这允许将广泛的类别细分为更具体的类别。例如,一个名为“Error”的标记,其子项名为“SystemError”和“ApplicationError”。
代码示例来源:origin: medcl/elasticsearch-analysis-ik
public String prefix() {
return this.marker.getName();
}
代码示例来源: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
@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-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-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
/**
* 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 boolean contains(final String s) {
return s != null ? this.marker.isInstanceOf(s) : false;
}
代码示例来源:origin: org.apache.logging.log4j.adapters/log4j-to-slf4j
private org.slf4j.Marker getMarker(final Marker marker) {
if (marker == null) {
return null;
}
final Marker parent = marker.getParent();
final org.slf4j.Marker parentMarker = parent == null ? null : getMarker(parent);
final org.slf4j.Marker slf4jMarker = MarkerFactory.getMarker(marker.getName());
if (parentMarker != null && !slf4jMarker.contains(parentMarker)) {
slf4jMarker.add(parentMarker);
}
return slf4jMarker;
}
代码示例来源: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-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-slf4j-impl
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Log4jMarker)) {
return false;
}
final Log4jMarker other = (Log4jMarker) obj;
if (marker == null) {
if (other.marker != null) {
return false;
}
} else if (!marker.equals(other.marker)) {
return false;
}
return true;
}
代码示例来源: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-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
@Override
public boolean contains(final org.slf4j.Marker marker) {
if (marker == null) {
throw new IllegalArgumentException();
}
return this.marker.isInstanceOf(marker.getName());
}
代码示例来源: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
if (localParents[0].equals(parent)) {
parents = null;
return true;
if (!marker.equals(parent)) {
if (index == localParentsLength - 1) {
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl
@Override
public String getName() {
return marker.getName();
}
代码示例来源: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
@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-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;
}
内容来源于网络,如有侵权,请联系作者删除!