当前位置: 首页>>代码示例>>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;未经允许,请勿转载。