本文整理匯總了Java中org.apache.logging.log4j.MarkerManager.getMarker方法的典型用法代碼示例。如果您正苦於以下問題:Java MarkerManager.getMarker方法的具體用法?Java MarkerManager.getMarker怎麽用?Java MarkerManager.getMarker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.MarkerManager
的用法示例。
在下文中一共展示了MarkerManager.getMarker方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCustomPattern
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
/**
* Test the custom pattern
*/
@Test
public void testCustomPattern() {
final List<PatternFormatter> formatters = parser.parse(customPattern);
assertNotNull(formatters);
final Map<String, String> mdc = new HashMap<String, String>();
mdc.put("loginId", "Fred");
final Throwable t = new Throwable();
final StackTraceElement[] elements = t.getStackTrace();
final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest", MarkerManager.getMarker("TEST"),
Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null,
mdc, null, "Thread1", elements[0], System.currentTimeMillis());
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
final String str = buf.toString();
final String expected = "INFO [PatternParserTest :96 ] - Hello, world" + Constants.LINE_SEP;
assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
示例2: testNestedPattern
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@Test
public void testNestedPattern() {
final List<PatternFormatter> formatters = parser.parse(nestedPattern);
assertNotNull(formatters);
final Throwable t = new Throwable();
final StackTraceElement[] elements = t.getStackTrace();
final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest", MarkerManager.getMarker("TEST"),
Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null, null, null, "Thread1", elements[0],
System.currentTimeMillis());
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
final String str = buf.toString();
final String expected = String.format("] INFO : Hello, world%s\u001B[m", Constants.LINE_SEP);
assertTrue(" Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
示例3: testConvert02
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@Test
public void testConvert02() {
final Marker marker = MarkerManager.getMarker("testConvert02",
MarkerManager.getMarker("anotherConvert02",
MarkerManager.getMarker("finalConvert03")
)
);
final String converted = this.converter.convertToDatabaseColumn(marker);
assertNotNull("The converted value should not be null.", converted);
assertEquals("The converted value is not correct.", "testConvert02[ anotherConvert02[ finalConvert03 ] ] ]",
converted);
final Marker reversed = this.converter.convertToEntityAttribute(converted);
assertNotNull("The reversed value should not be null.", reversed);
assertEquals("The reversed value is not correct.", "testConvert02", marker.getName());
assertNotNull("The first parent should not be null.", marker.getParent());
assertEquals("The first parent is not correct.", "anotherConvert02", marker.getParent().getName());
assertNotNull("The second parent should not be null.", marker.getParent().getParent());
assertEquals("The second parent is not correct.", "finalConvert03", marker.getParent().getParent().getName());
}
示例4: testAddMarker
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@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));
}
示例5: setUp
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
this.configFile = new File(this.temporaryFolder.getRoot(), "log4j2-test.xml");
this.configFileLocation = this.configFile.toURI().toURL().toString();
this.enabledMarker = MarkerManager.getMarker(ENABLED_MARKER_NAME);
this.unusedMarker = MarkerManager.getMarker(UNUSED_MARKER_NAME);
setUpLogService();
}
示例6: AbstractState
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
public AbstractState(StateContext context) {
this.logger = LogManager.getLogger(getClass());
this.marker = MarkerManager.getMarker("StateMachine");
this.isActive = new AtomicBoolean();
this.context = context;
this.conditionalMap = new HashMap<>();
}
示例7: testMarker
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@Test
public void testMarker() {
final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker("TEST");
final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker("PARENT");
slf4jMarker.add(slf4jParent);
final Marker log4jParent = MarkerManager.getMarker("PARENT");
final Marker log4jMarker = MarkerManager.getMarker("TEST", log4jParent);
assertTrue("Incorrect Marker class", slf4jMarker instanceof MarkerWrapper);
assertTrue("SLF4J Marker doesn't match Log4j Marker", ((MarkerWrapper) slf4jMarker).isInstanceOf(log4jMarker));
assertTrue("SLF4J Parent doesn't match Log4j parent", ((MarkerWrapper) slf4jMarker).isInstanceOf(log4jParent));
}
示例8: testSingle
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@Test
public void testSingle() throws InterruptedException, IOException {
final Logger logger = LogManager.getLogger("EventLogger");
final Marker marker = MarkerManager.getMarker("EVENT");
logger.info(marker, "This is a test message");
final Event event = primary.poll();
Assert.assertNotNull(event);
final String body = getBody(event);
Assert.assertTrue("Channel contained event, but not expected message. Received: " + body,
body.endsWith("This is a test message"));
}
示例9: logAndCheck
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
private void logAndCheck() {
final Marker marker = MarkerManager.getMarker("HEXDUMP");
final Logger logger = loggerContextRule.getLogger(DefaultRouteScriptAppenderTest.class);
logger.error("Hello");
final ListAppender listAppender = getListAppender();
final List<LogEvent> list = listAppender.getEvents();
assertNotNull("No events generated", list);
assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
logger.error("World");
assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
logger.error(marker, "DEADBEEF");
assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
示例10: testLookup
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@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", eventMarker);
final LogEvent event = new Log4jLogEvent("MyLogger", auditMarker, null, Level.DEBUG, msg, null);
final StringBuilder sb = new StringBuilder();
final MarkerPatternConverter converter = MarkerPatternConverter.newInstance(null);
converter.format(event, sb);
assertEquals(auditMarker.toString(), sb.toString());
}
示例11: testLookup
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@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());
}
示例12: testConvert01
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@Test
public void testConvert01() {
final Marker marker = MarkerManager.getMarker("testConvert01");
final String converted = this.converter.convertToDatabaseColumn(marker);
assertNotNull("The converted value should not be null.", converted);
assertEquals("The converted value is not correct.", "testConvert01", converted);
final Marker reversed = this.converter.convertToEntityAttribute(converted);
assertNotNull("The reversed value should not be null.", reversed);
assertEquals("The reversed value is not correct.", "testConvert01", marker.getName());
}
示例13: testAddSameMarker
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@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));
}
示例14: testContainsNullString
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@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));
}
示例15: testRemoveNullMarker
import org.apache.logging.log4j.MarkerManager; //導入方法依賴的package包/類
@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));
}