本文整理匯總了Java中org.apache.logging.log4j.MarkerManager類的典型用法代碼示例。如果您正苦於以下問題:Java MarkerManager類的具體用法?Java MarkerManager怎麽用?Java MarkerManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MarkerManager類屬於org.apache.logging.log4j包,在下文中一共展示了MarkerManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PrefixLogger
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
PrefixLogger(final ExtendedLogger logger, final String name, final String prefix) {
super(logger, name, null);
final String actualPrefix = (prefix == null ? "" : prefix).intern();
final Marker actualMarker;
// markers is not thread-safe, so we synchronize access
synchronized (markers) {
final WeakReference<Marker> marker = markers.get(actualPrefix);
final Marker maybeMarker = marker == null ? null : marker.get();
if (maybeMarker == null) {
actualMarker = new MarkerManager.Log4jMarker(actualPrefix);
markers.put(actualPrefix, new WeakReference<>(actualMarker));
} else {
actualMarker = maybeMarker;
}
}
this.marker = actualMarker;
}
示例2: integrationTestAfter5
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
/**
* Integration test that asserts events are sent to the Elastic cluster in bulk.
*
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void integrationTestAfter5() throws IOException {
String test = "integration-test-after-5";
Logger logger = getLogger(test);
ElasticClient client = new ElasticClient(logger);
String marker = getUniqueMarker();
// Should not send until it reaches 5 events
for (int i = 1; i < 5; i++) {
logger.error(MarkerManager.getMarker(marker), i + "-" + test);
}
JsonNode doc = client.findFirstByMarker(marker);
assertNull(doc);
// But after the 5th event it should send all buffered events
logger.error(MarkerManager.getMarker(marker), "5-" + test);
JsonNode hits = client.findAllByMarker(marker);
assertNotNull(hits);
assertEquals(5, hits.size());
for (int i = 0; i < 5; i++) {
assertFieldValue(hits.get(i).get("_source"), "level", "ERROR");
assertFieldValue(hits.get(i).get("_source"), "message", (i + 1) + "-" + test);
}
}
示例3: createLogEvent
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
private LogEvent createLogEvent(DateTime timestamp) {
final MutableLogEvent logEvent = new MutableLogEvent();
logEvent.setMessage(new SimpleMessage("Test"));
logEvent.setLevel(Level.TRACE);
logEvent.setLoggerName("org.example.Test");
logEvent.setMarker(MarkerManager.getMarker("TestMarker"));
logEvent.setTimeMillis(timestamp.getMillis());
logEvent.setNanoTime(42L);
logEvent.setContextStack(new MutableThreadContextStack(ImmutableList.of("one", "two")));
final SortedArrayStringMap contextData = new SortedArrayStringMap(1);
contextData.putValue("foobar", "quux");
logEvent.setContextData(contextData);
logEvent.setThreadId(23L);
logEvent.setThreadName("thread-name");
logEvent.setThreadPriority(42);
logEvent.setThrown(new Throwable("Test", new Throwable("cause")));
logEvent.setIncludeLocation(true);
return logEvent.createMemento();
}
示例4: 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));
}
示例5: 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));
}
示例6: 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());
}
示例7: initXlsLogger
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
private void initXlsLogger() {
try {
// Prepare application string
String applicationVersion = getConfiguration().getString("application.version", "0.0.1");
applicationVersion += "." + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
// Init Logger
File outputDirectory = new File(s_xlsLoggerOutputPath);
m_xlsLogger = new XlsLogger(outputDirectory, s_xlsLoggerOutputFileName, s_xlsLoggerInitialSheetName,
applicationVersion);
} catch (Exception e) {
m_log.error(MarkerManager.getMarker("EXCEPTION"), "Error while opening XLS logger.", e);
m_xlsLogger = null;
}
}
示例8: ContentLoader
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
public ContentLoader(String baseUrl, int basePort, String restEndpoint, FishWorld fishWorld) {
m_fishWorld = fishWorld;
// Initialize CommunityMashup
ConnectionManager.init(baseUrl, basePort, restEndpoint);
// Initialize ContentCollector
m_contentCollector = new ContentCollectRunnable();
// Begin data collection after short delay
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(START_SLEEP);
} catch (InterruptedException e) {
m_log.warn(MarkerManager.getMarker("EXCEPTION"), "BeginDataCollection sleep interrupted.");
}
beginDataCollection();
}
}).start();
}
示例9: testSimpleInfo
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
@Test
public void testSimpleInfo() throws Exception {
Logger logger = loggerContext.getLogger(getClass().getName());
logger.info(new MarkerManager.Log4jMarker("test"), LOG_MESSAGE);
assertThat(GelfTestSender.getMessages()).hasSize(1);
GelfMessage gelfMessage = GelfTestSender.getMessages().get(0);
assertThat(gelfMessage.getFullMessage()).isEqualTo(EXPECTED_LOG_MESSAGE);
assertThat(gelfMessage.getShortMessage()).isEqualTo(EXPECTED_LOG_MESSAGE);
assertThat(gelfMessage.getField("MyTime")).isNotNull();
assertThat(gelfMessage.getAdditonalFields().get("Marker")).isEqualTo("test");
assertThat(gelfMessage.getLevel()).isEqualTo("6");
assertThat(gelfMessage.getField(LogMessageField.NamedLogField.SourceLineNumber.name())).isNotNull();
assertThat(gelfMessage.getField(LogMessageField.NamedLogField.SourceMethodName.name())).isEqualTo("testSimpleInfo");
assertThat(gelfMessage.getField(LogMessageField.NamedLogField.SourceClassName.name())).isEqualTo(getClass().getName());
}
示例10: convertMarker
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
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;
}
示例11: 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));
}
示例12: testEquals
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
@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);
}
示例13: testConvert02
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
@Test
public void testConvert02() {
Marker marker = MarkerManager.getMarker("anotherConvert02").setParents(MarkerManager.getMarker("finalConvert03"));
marker = MarkerManager.getMarker("testConvert02").setParents(marker);
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());
final Marker[] parents = marker.getParents();
assertNotNull("The first parent should not be null.", parents);
assertNotNull("The first parent should not be null.", parents[0]);
assertEquals("The first parent is not correct.", "anotherConvert02", parents[0].getName());
assertNotNull("The second parent should not be null.", parents[0].getParents());
assertNotNull("The second parent should not be null.", parents[0].getParents()[0]);
assertEquals("The second parent is not correct.", "finalConvert03", parents[0].getParents()[0].getName());
}
示例14: testNestedPatternHighlight
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
private void testNestedPatternHighlight(final Level level, final String expectedStart) {
final List<PatternFormatter> formatters = parser.parse(nestedPatternHighlight);
assertNotNull(formatters);
final Throwable t = new Throwable();
t.getStackTrace();
final LogEvent event = Log4jLogEvent.newBuilder() //
.setLoggerName("org.apache.logging.log4j.PatternParserTest") //
.setMarker(MarkerManager.getMarker("TEST")) //
.setLoggerFqcn(Logger.class.getName()) //
.setLevel(level) //
.setMessage(new SimpleMessage("Hello, world")) //
.setThreadName("Thread1") //
.setSource(/*stackTraceElement[0]*/ null) //
.setTimeMillis(System.currentTimeMillis()) //
.build();
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
final String str = buf.toString();
final String expectedEnd = String.format("] %-5s: Hello, world%s\u001B[m", level, Strings.LINE_SEPARATOR);
assertTrue("Expected to start with: " + expectedStart + ". Actual: " + str, str.startsWith(expectedStart));
assertTrue("Expected to end with: \"" + expectedEnd + "\". Actual: \"" + str, str.endsWith(expectedEnd));
}
示例15: testPatternSelector
import org.apache.logging.log4j.MarkerManager; //導入依賴的package包/類
@Test
public void testPatternSelector() throws Exception {
final PatternMatch[] patterns = new PatternMatch[1];
patterns[0] = new PatternMatch("FLOW", "%d %-5p [%t]: ====== %C{1}.%M:%L %m ======%n");
final PatternSelector selector = MarkerPatternSelector.createSelector(patterns, "%d %-5p [%t]: %m%n", true, true, ctx.getConfiguration());
final PatternLayout layout = PatternLayout.newBuilder().withPatternSelector(selector)
.withConfiguration(ctx.getConfiguration()).build();
final LogEvent event1 = Log4jLogEvent.newBuilder() //
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.layout.PatternSelectorTest$FauxLogger")
.setMarker(MarkerManager.getMarker("FLOW"))
.setLevel(Level.TRACE) //
.setIncludeLocation(true)
.setMessage(new SimpleMessage("entry")).build();
final String result1 = new FauxLogger().formatEvent(event1, layout);
final String expectSuffix1 = String.format("====== PatternSelectorTest.testPatternSelector:53 entry ======%n");
assertTrue("Unexpected result: " + result1, result1.endsWith(expectSuffix1));
final LogEvent event2 = Log4jLogEvent.newBuilder() //
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
.setLevel(Level.INFO) //
.setMessage(new SimpleMessage("Hello, world 1!")).build();
final String result2 = new String(layout.toByteArray(event2));
final String expectSuffix2 = String.format("Hello, world 1!%n");
assertTrue("Unexpected result: " + result2, result2.endsWith(expectSuffix2));
}