本文整理了Java中org.apache.logging.log4j.message.Message.getFormat()
方法的一些代码示例,展示了Message.getFormat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getFormat()
方法的具体详情如下:
包路径:org.apache.logging.log4j.message.Message
类名称:Message
方法名:getFormat
[英]Gets the format portion of the Message.
[中]获取消息的格式部分。
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Override
public String getFormat() {
if (message != null) {
return text + ": " + message.getFormat();
}
return text;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void paramWithExceptionTest() throws Exception {
logger.error("Throwing with parameters {}", "TestParam", new NullPointerException("Test Exception"));
final List<LogEvent> events = app.getEvents();
assertNotNull("Log event list not returned", events);
assertEquals("Incorrect number of log events", 1, events.size());
final LogEvent event = events.get(0);
final Throwable thrown = event.getThrown();
assertNotNull("No throwable present in log event", thrown);
final Message msg = event.getMessage();
assertEquals("Throwing with parameters {}", msg.getFormat());
assertEquals("Throwing with parameters TestParam", msg.getFormattedMessage());
assertArrayEquals(new Object[] { "TestParam", thrown }, msg.getParameters());
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
assertEquals("parameters", new String[] {"bottle"}, mutable.getParameters());
Message memento = mutable.memento();
assertEquals("format", "msg in a {}", memento.getFormat());
assertEquals("formatted", "msg in a bottle", memento.getFormattedMessage());
assertEquals("parameters", new String[] {"bottle"}, memento.getParameters());
assertEquals("format", "msg in a {}", eventMementoMessage.getFormat());
assertEquals("formatted", "msg in a bottle", eventMementoMessage.getFormattedMessage());
assertEquals("parameters", new String[] {"bottle"}, eventMementoMessage.getParameters());
assertEquals("format", "msg in a {}", log4JLogEventMessage.getFormat());
assertEquals("formatted", "msg in a bottle", log4JLogEventMessage.getFormattedMessage());
assertEquals("parameters", new String[] {"bottle"}, log4JLogEventMessage.getParameters());
代码示例来源:origin: org.apache.logging.log4j/log4j-api
private void handleLogMessageException(final Exception exception, final String fqcn, final Message msg) {
if (exception instanceof LoggingException) {
throw (LoggingException) exception;
}
final String format = msg.getFormat();
final int formatLength = format == null ? 4 : format.length();
final StringBuilder sb = new StringBuilder(formatLength + 100);
sb.append(fqcn);
sb.append(" caught ");
sb.append(exception.getClass().getName());
sb.append(" logging ");
sb.append(msg.getClass().getSimpleName());
sb.append(": ");
sb.append(format);
StatusLogger.getLogger().warn(sb.toString(), exception);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testCreateMementoRetainsParametersAndFormat() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
// Initialize the event with parameters
evt.swapParameters(new Object[10]);
final String loggerName = "logger.name";
final Marker marker = MarkerManager.getMarker("marked man");
final String fqcn = "f.q.c.n";
final Level level = Level.TRACE;
ReusableMessageFactory factory = new ReusableMessageFactory();
Message message = factory.newMessage("Hello {}!", "World");
try {
final Throwable t = new InternalError("not a real error");
final ContextStack contextStack = new MutableThreadContextStack(Arrays.asList("a", "b"));
final String threadName = "main";
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, message, t, (StringMap) evt.getContextData(),
contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
((StringMap) evt.getContextData()).putValue("key", "value");
final Message actual = evt.createMemento().getMessage();
assertEquals("Hello {}!", actual.getFormat());
assertArrayEquals(new String[]{"World"}, actual.getParameters());
assertEquals("Hello World!", actual.getFormattedMessage());
} finally {
ReusableMessageFactory.release(message);
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
toAppendTo.append(event.getMessage().getFormat());
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg,
final Throwable t) {
if (msg == null) {
return onMismatch;
}
final String text = useRawMessage ? msg.getFormat() : msg.getFormattedMessage();
return filter(text);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@Override
public String getFormat() {
if (message != null) {
return text + ": " + message.getFormat();
}
return text;
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@Override
public Result filter(final LogEvent event) {
final String text = useRawMessage ? event.getMessage().getFormat() : event.getMessage().getFormattedMessage();
return filter(text);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
private void handleLogMessageException(final Exception exception, final String fqcn, final Message msg) {
if (exception instanceof LoggingException) {
throw (LoggingException) exception;
}
final String format = msg.getFormat();
final StringBuilder sb = new StringBuilder(format.length() + 100);
sb.append(fqcn);
sb.append(" caught ");
sb.append(exception.getClass().getName());
sb.append(" logging ");
sb.append(msg.getClass().getSimpleName());
sb.append(": ");
sb.append(format);
StatusLogger.getLogger().warn(sb.toString(), exception);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
private void appendMessage(final StringBuilder buffer, final LogEvent event) {
final Message message = event.getMessage();
// This layout formats StructuredDataMessages instead of delegating to the Message itself.
final String text = (message instanceof StructuredDataMessage || message instanceof MessageCollectionMessage)
? message.getFormat() : message.getFormattedMessage();
if (text != null && text.length() > 0) {
buffer.append(' ').append(escapeNewlines(text, escapeNewLine));
}
if (exceptionFormatters != null && event.getThrown() != null) {
final StringBuilder exception = new StringBuilder(LF);
for (final PatternFormatter formatter : exceptionFormatters) {
formatter.format(event, exception);
}
buffer.append(escapeNewlines(exception.toString(), escapeNewLine));
}
if (includeNewLine) {
buffer.append(LF);
}
}
代码示例来源:origin: javabeanz/owasp-security-logging
Message outMessage = new ParameterizedMessage(msg.getFormat(), params,
msg.getThrowable());
代码示例来源:origin: io.sentry/sentry-log4j2
.withExtra(THREAD_NAME, event.getThreadName());
if (eventMessage.getFormat() != null
&& !eventMessage.getFormat().equals("")
&& !eventMessage.getFormattedMessage().equals(eventMessage.getFormat())) {
eventBuilder.withSentryInterface(new MessageInterface(
eventMessage.getFormat(),
formatMessageParameters(eventMessage.getParameters()),
eventMessage.getFormattedMessage()));
代码示例来源:origin: com.getsentry.raven/raven-log4j2
if (eventMessage.getFormat() != null
&& !eventMessage.getFormat().equals("")
&& !eventMessage.getFormattedMessage().equals(eventMessage.getFormat())) {
eventBuilder.withSentryInterface(new MessageInterface(
eventMessage.getFormat(),
formatMessageParameters(eventMessage.getParameters()),
eventMessage.getFormattedMessage()));
内容来源于网络,如有侵权,请联系作者删除!