本文整理了Java中org.slf4j.Marker.add()
方法的一些代码示例,展示了Marker.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marker.add()
方法的具体详情如下:
包路径:org.slf4j.Marker
类名称:Marker
方法名:add
[英]Add a reference to another Marker.
[中]添加对另一个标记的引用。
代码示例来源: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: org.apache.logging.log4j/log4j-slf4j-impl
@Test
public void testAddMarker() {
final String childMakerName = CHILD_MAKER_NAME + "-AM";
final String parentMarkerName = PARENT_MARKER_NAME + "-AM";
final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName);
final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMarkerName);
slf4jMarker.add(slf4jParent);
final Marker log4jParent = MarkerManager.getMarker(parentMarkerName);
final Marker log4jMarker = MarkerManager.getMarker(childMakerName);
assertTrue("Incorrect Marker class", slf4jMarker instanceof Log4jMarker);
assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j",
childMakerName, parentMarkerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent));
assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J",
childMakerName, parentMarkerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent));
}
代码示例来源: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: org.apache.logging.log4j/log4j-slf4j-impl
@Test
public void testContainsNullMarker() {
final String childMarkerName = CHILD_MAKER_NAME + "-CM";
final String parentMakerName = PARENT_MARKER_NAME + "-CM";
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 {
Assert.assertFalse(log4jSlf4jParent.contains(nullMarker));
fail("Expected " + IllegalArgumentException.class.getName());
} catch (final IllegalArgumentException e) {
// expected
}
try {
Assert.assertFalse(log4jSlf4jMarker.contains(nullMarker));
fail("Expected " + IllegalArgumentException.class.getName());
} catch (final IllegalArgumentException e) {
// expected
}
}
代码示例来源: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: org.apache.logging.log4j/log4j-slf4j-impl
@Test
public void testRemoveNullMarker() {
final String childMakerName = CHILD_MAKER_NAME + "-CM";
final String parentMakerName = PARENT_MARKER_NAME + "-CM";
final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName);
final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName);
slf4jMarker.add(slf4jParent);
final Marker log4jParent = MarkerManager.getMarker(parentMakerName);
final Marker log4jMarker = MarkerManager.getMarker(childMakerName);
final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent);
final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker);
final org.slf4j.Marker nullMarker = null;
Assert.assertFalse(log4jSlf4jParent.remove(nullMarker));
Assert.assertFalse(log4jSlf4jMarker.remove(nullMarker));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl
@Test
public void testContainsNullString() {
final String childMarkerName = CHILD_MAKER_NAME + "-CS";
final String parentMakerName = PARENT_MARKER_NAME + "-CS";
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 String nullStr = null;
Assert.assertFalse(log4jSlf4jParent.contains(nullStr));
Assert.assertFalse(log4jSlf4jMarker.contains(nullStr));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-slf4j-impl
@Test
public void testEquals() {
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 slf4jMarker2 = 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 Marker log4jMarker2 = MarkerManager.getMarker(childMarkerName);
assertEquals(log4jParent, log4jParent);
assertEquals(log4jMarker, log4jMarker);
assertEquals(log4jMarker, log4jMarker2);
assertEquals(slf4jMarker, slf4jMarker2);
assertNotEquals(log4jParent, log4jMarker);
assertNotEquals(log4jMarker, log4jParent);
}
代码示例来源: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: sixt/ja-micro
public Marker getLoggingMarker() {
// If we get more optional header fields, we should probably exclude them if they are empty.
Marker messageMarker =
append("messageId", messageId)
.and(append("partitionId", partitionId))
.and(append("partitioningKey", partitioningKey))
.and(append("offset", offset))
.and(append("messageId", messageId))
.and(append("correlationId", correlationId))
.and(append("requestCorrelationId", requestCorrelationId));
// Nota bene: without the toString the marker tries to convert the object into Json, which produces strange results
if (topic != null) {
messageMarker.add(append("topic", topic.toString()));
}
if (replyTo != null) {
messageMarker.add(append("replyTo", replyTo.toString()));
}
if (type != null) {
messageMarker.add(append("messageType", type.toString()));
}
return messageMarker;
}
代码示例来源:origin: allegro/hermes
private Marker getEnrichedMarker(Marker marker) {
if (marker == null) {
return MARKER;
}
marker.add(MARKER);
return marker;
}
代码示例来源:origin: com.atlassian.selenium/atlassian-performance
public void startTest(Test test) {
System.out.println("Adding marker for " + test);
Marker perfMarker = MarkerFactory.getMarker(PERF_MARKER_TOKEN);
perfMarker.add(MarkerFactory.getMarker(test.getClass().toString()));
}
代码示例来源:origin: godaddy/godaddy-logger
@Override
public void trace(Marker marker, String msg) {
marker.add(formatMessage(getMessage(msg)));
root.trace(marker, msg);
}
代码示例来源:origin: godaddy/godaddy-logger
@Override
public void trace(Marker marker, String format, Object arg1, Object arg2) {
marker.add(formatMessage(getMessage(format)));
root.trace(marker, format, arg1, arg2);
}
代码示例来源:origin: godaddy/godaddy-logger
@Override
public void trace(Marker marker, String format, Object arg) {
marker.add(formatMessage(getMessage(format)));
root.trace(marker, format, arg);
}
代码示例来源:origin: godaddy/godaddy-logger
@Override
public void info(Marker marker, String msg, Throwable t) {
marker.add(formatMessage(getMessage(msg)));
root.info(marker, msg, t);
}
代码示例来源:origin: godaddy/godaddy-logger
@Override
public void warn(Marker marker, String format, Object... arguments) {
marker.add(formatMessage(getMessage(format)));
root.warn(marker, format, arguments);
}
代码示例来源:origin: net.sf.grinder/grinder-core
@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: tony19/logback-android
@Test
public void testWithSeveralChildMarker() {
Marker marker = markerFactory.getMarker("testParent");
marker.add(markerFactory.getMarker("child1"));
marker.add(markerFactory.getMarker("child2"));
marker.add(markerFactory.getMarker("child3"));
String result = converter.convert(createLoggingEvent(marker));
assertEquals("testParent [ child1, child2, child3 ]", result);
}
代码示例来源:origin: tony19/logback-android
@Test
public void testWithOneChildMarker() {
Marker marker = markerFactory.getMarker("test");
marker.add(markerFactory.getMarker("child"));
String result = converter.convert(createLoggingEvent(marker));
assertEquals("test [ child ]", result);
}
内容来源于网络,如有侵权,请联系作者删除!