本文整理汇总了Java中org.apache.logging.log4j.message.Message.getFormattedMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getFormattedMessage方法的具体用法?Java Message.getFormattedMessage怎么用?Java Message.getFormattedMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.message.Message
的用法示例。
在下文中一共展示了Message.getFormattedMessage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logMessage
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
public void logMessage(String string, Level level, Marker marker, Message message, Throwable t) {
String msg = message.getFormattedMessage();
msg = MessageFormat.format(msg, message.getParameters());
if (level == Level.ALL) {
logger.log(java.util.logging.Level.ALL, msg, t);
} else if (level == Level.DEBUG) {
logger.log(java.util.logging.Level.FINEST, msg, t);
} else if (level == Level.ERROR) {
logger.log(java.util.logging.Level.SEVERE, msg, t);
} else if (level == Level.FATAL) {
logger.log(java.util.logging.Level.SEVERE, msg, t);
} else if (level == Level.INFO) {
logger.log(java.util.logging.Level.INFO, msg, t);
} else if (level == Level.OFF) {
logger.log(java.util.logging.Level.OFF, msg, t);
} else if (level == Level.TRACE) {
logger.log(java.util.logging.Level.SEVERE, msg, t);
} else if (level == Level.WARN) {
logger.log(java.util.logging.Level.WARNING, msg, t);
} else {
logger.log(java.util.logging.Level.INFO, msg, t);
}
}
示例2: format
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
final Message msg = event.getMessage();
if (msg != null) {
String result;
if (msg instanceof MultiformatMessage) {
result = ((MultiformatMessage) msg).getFormattedMessage(formats);
} else {
result = msg.getFormattedMessage();
}
if (result != null) {
toAppendTo.append(config != null && result.contains("${") ?
config.getStrSubstitutor().replace(event, result) : result);
} else {
toAppendTo.append("null");
}
}
}
示例3: log
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* Logs a message with location information by redirecting it to the underlaying {@link java.util.logging.Logger}.
*
* @param marker the Marker
* @param fqcn the fully qualified class name of the <b>caller</b>
* @param level the logging level
* @param data the Message.
* @param t a Throwable or null.
*/
@Override
public void log(Marker marker, String fqcn, Level level, Message data, Throwable t) {
final String msg;
String mkName = (marker == null) ? "" : marker.getName();
if (this.format == null) {
if (mkName.isEmpty()) {
msg = data.getFormattedMessage();
} else {
msg = String.format(DEFAULT_FORMAT, data.getFormattedMessage(), mkName);
}
} else {
msg = String.format(this.format, data.getFormattedMessage(), mkName);
}
LogRecord record = new LogRecord(Util.levelToJUL(level), msg);
record.setThrown(t);
record.setSourceClassName(fqcn);
record.setLoggerName(this.jul.getName());
this.jul.log(record);
}
示例4: format
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
final Message msg = event.getMessage();
if (msg != null) {
String result;
if (msg instanceof NoGcMessage) {
toAppendTo.append(((NoGcMessage) msg).get());
return;
}
if (msg instanceof MultiformatMessage) {
result = ((MultiformatMessage) msg).getFormattedMessage(formats);
} else {
result = msg.getFormattedMessage();
}
if (result != null) {
toAppendTo.append(config != null && result.contains("${") ?
config.getStrSubstitutor().replace(event, result) : result);
} else {
toAppendTo.append("null");
}
}
}
示例5: appendMessage
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
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);
}
}
示例6: append
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
@Override
public void append(LogEvent event) {
Message message = event.getMessage();
String text = message.getFormattedMessage();
MinecraftForge.EVENT_BUS
.post(new ServerLog4jEvent(text));
}
示例7: getMessage
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* Gets the log message from the event
* @param event The event
* @return The log message
*/
public String getMessage(final LogEvent event) {
Message message = event.getMessage();
if (message != null) {
return message.getFormattedMessage();
}
return null;
}
示例8: convertToDatabaseColumn
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
@Override
public String convertToDatabaseColumn(final Message message) {
if (message == null) {
return null;
}
return message.getFormattedMessage();
}
示例9: filter
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
@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);
}
示例10: filter
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
@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);
}
示例11: format
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
final Message msg = event.getMessage();
if (msg instanceof StringBuilderFormattable) {
final boolean doRender = textRenderer != null;
final StringBuilder workingBuilder = doRender ? new StringBuilder(80) : toAppendTo;
final int offset = workingBuilder.length();
if (msg instanceof MultiFormatStringBuilderFormattable) {
((MultiFormatStringBuilderFormattable) msg).formatTo(formats, workingBuilder);
} else {
((StringBuilderFormattable) msg).formatTo(workingBuilder);
}
// TODO can we optimize this?
if (config != null && !noLookups) {
for (int i = offset; i < workingBuilder.length() - 1; i++) {
if (workingBuilder.charAt(i) == '$' && workingBuilder.charAt(i + 1) == '{') {
final String value = workingBuilder.substring(offset, workingBuilder.length());
workingBuilder.setLength(offset);
workingBuilder.append(config.getStrSubstitutor().replace(event, value));
}
}
}
if (doRender) {
textRenderer.render(workingBuilder, toAppendTo);
}
return;
}
if (msg != null) {
String result;
if (msg instanceof MultiformatMessage) {
result = ((MultiformatMessage) msg).getFormattedMessage(formats);
} else {
result = msg.getFormattedMessage();
}
if (result != null) {
toAppendTo.append(config != null && result.contains("${")
? config.getStrSubstitutor().replace(event, result) : result);
} else {
toAppendTo.append("null");
}
}
}
示例12: transform
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* Returns a new {@code Message} based on the original message that appends an internal Log4j2 message
* explaining why this message appears out of order in the appender.
* <p>
* Any parameter objects present in the original message are not included in the returned message.
* </p>
* @param message the message to replace
* @return a new {@code Message} object
*/
public static Message transform(Message message) {
SimpleMessage result = new SimpleMessage(message.getFormattedMessage() +
" (Log4j2 logged this message out of order to prevent deadlock caused by domain " +
"objects logging from their toString method when the async queue is full - LOG4J2-2031)");
return result;
}
示例13: makeMessageImmutable
import org.apache.logging.log4j.message.Message; //导入方法依赖的package包/类
/**
* Returns the specified message, with its content frozen unless system property
* {@code log4j.format.msg.async} is true or the message class is annotated with
* {@link AsynchronouslyFormattable}.
*
* @param msg the message object to inspect, modify and return
* @return Returns the specified message, with its content frozen
*/
public static Message makeMessageImmutable(final Message msg) {
// if the Message instance is reused, there is no point in freezing its message here
if (msg != null && !canFormatMessageInBackground(msg)) {
msg.getFormattedMessage(); // LOG4J2-763: ask message to makeMessageImmutable parameters
}
return msg;
}