當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.getFormattedMessage方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:mc-societies,項目名稱:societies,代碼行數:26,代碼來源:LoggerWrapper.java

示例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");
        }
    }
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:22,代碼來源:MessagePatternConverter.java

示例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);
}
 
開發者ID:Wolf480pl,項目名稱:log4j2-to-jul,代碼行數:29,代碼來源:JULLogger.java

示例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");
        }
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:26,代碼來源:NoGcMessagePatternConverter.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:22,代碼來源:Rfc5424Layout.java

示例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));
}
 
開發者ID:wizards-of-lua,項目名稱:wizards-of-lua,代碼行數:8,代碼來源:Log4j2ForgeEventBridge.java

示例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;
}
 
開發者ID:stackify,項目名稱:stackify-log-log4j2,代碼行數:16,代碼來源:LogEventAdapter.java

示例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();
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:9,代碼來源:MessageAttributeConverter.java

示例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);
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:10,代碼來源:RegexFilter.java

示例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);
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:10,代碼來源:RegexFilter.java

示例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");
        }
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:49,代碼來源:MessagePatternConverter.java

示例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;
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:16,代碼來源:AsyncQueueFullMessageUtil.java

示例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;
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:16,代碼來源:InternalAsyncUtil.java


注:本文中的org.apache.logging.log4j.message.Message.getFormattedMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。