java.util.logging.Formatter.formatMessage()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中java.util.logging.Formatter.formatMessage()方法的一些代码示例,展示了Formatter.formatMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Formatter.formatMessage()方法的具体详情如下:
包路径:java.util.logging.Formatter
类名称:Formatter
方法名:formatMessage

Formatter.formatMessage介绍

[英]Formats a LogRecord object into a localized string representation. This is a convenience method for subclasses of Formatter.

The message string is firstly localized using the ResourceBundleobject associated with the supplied LogRecord.

Notice : if message contains "{0", then java.text.MessageFormat is used. Otherwise no formatting is performed.
[中]将LogRecord对象格式化为本地化字符串表示形式。这是格式化程序子类的一种方便方法。
首先使用与提供的日志记录关联的ResourceBundleobject对消息字符串进行本地化。
注意:若消息包含“{0”,则使用java.text.MessageFormat。否则不执行格式化。

代码示例

代码示例来源:origin: apache/geode

private String getMessage(final LogRecord record) {
 StringBuilder stringBuilder = new StringBuilder();
 stringBuilder.append('(').append("tid=").append(record.getThreadID())
   .append(" msgId=").append(record.getSequenceNumber()).append(") ");
 if (record.getMessage() != null) {
  stringBuilder.append(getFormatter().formatMessage(record));
 }
 return stringBuilder.toString();
}

代码示例来源:origin: stackoverflow.com

.append(record.getLevel().getLocalizedName())
.append(": ")
.append(formatMessage(record))
.append(LINE_SEPARATOR);

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Formats message for the log record. This method removes any fully
 * qualified throwable class names from the message.
 *
 * @param record the log record.
 * @return the formatted message string.
 */
@Override
public String formatMessage(final LogRecord record) {
  String msg = super.formatMessage(record);
  msg = replaceClassName(msg, record.getThrown());
  msg = replaceClassName(msg, record.getParameters());
  return msg;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Formats message for the log record. This method removes any fully
 * qualified throwable class names from the message.
 *
 * @param record the log record.
 * @return the formatted message string.
 */
@Override
public String formatMessage(final LogRecord record) {
  String msg = super.formatMessage(record);
  msg = replaceClassName(msg, record.getThrown());
  msg = replaceClassName(msg, record.getParameters());
  return msg;
}

代码示例来源:origin: danfickle/openhtmltopdf

/**
 * Localize and format the message string from a log record.
 *
 * @param record  PARAM
 * @return        Returns
 */
public String formatMessage( LogRecord record ) {
  return super.formatMessage( record );
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.xhtmlrenderer/core-renderer

/**
 * Localize and format the message string from a log record.
 *
 * @param record  PARAM
 * @return        Returns
 */
public String formatMessage( LogRecord record ) {
  return super.formatMessage( record );
}

代码示例来源:origin: org.docx4j/xhtmlrenderer

/**
 * Localize and format the message string from a log record.
 *
 * @param record  PARAM
 * @return        Returns
 */
public String formatMessage( LogRecord record ) {
  return super.formatMessage( record );
}

代码示例来源:origin: org.xhtmlrenderer/core-renderer

/**
 * Localize and format the message string from a log record.
 *
 * @param record  PARAM
 * @return        Returns
 */
public String formatMessage( LogRecord record ) {
  return super.formatMessage( record );
}

代码示例来源:origin: org.wso2.carbon/org.wso2.carbon.bootstrap

public static LogRecord formatMessage(Formatter formatter, LogRecord record) {
  record.setMessage(formatter.formatMessage(record));
  record.setSourceClassName(record.getSourceClassName());
  return record;
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

@Override
  public synchronized void publish(LogRecord record) {
    super.publish(record);
    String message = f.formatMessage(record);
    Throwable x = record.getThrown();
    messages.add(message == null && x != null ? x.toString() : message);
  }
};

代码示例来源:origin: com.scireum/sirius-kernel

@Override
public void publish(LogRecord record) {
  repository.getLogger(record.getLoggerName() == null ? "unknown" : record.getLoggerName())
       .log(Log.convertJuliLevel(record.getLevel()),
          formatter.formatMessage(record),
          record.getThrown());
}

代码示例来源:origin: io.snappydata/gemfire-core

private String getMessage(LogRecord record) {
 final StringBuilder b = new StringBuilder();
 b .append('(')
  .append("tid=" + record.getThreadID())
  .append(" msgId=" + record.getSequenceNumber())
  .append(") ");
 if (record.getMessage() != null) {
  b.append(getFormatter().formatMessage(record));
 }
 return b.toString();
}

代码示例来源:origin: org.apache.geode/gemfire-core

private String getMessage(LogRecord record) {
 final StringBuilder b = new StringBuilder();
 b .append('(')
  .append("tid=" + record.getThreadID())
  .append(" msgId=" + record.getSequenceNumber())
  .append(") ");
 if (record.getMessage() != null) {
  b.append(getFormatter().formatMessage(record));
 }
 return b.toString();
}

代码示例来源:origin: com.ebmwebsourcing.easycommons/easycommons-logger

@Override
  public synchronized String formatMessage(LogRecord record) {
    Object[] extraParameters = record.getParameters();
    String result = null;
    if (isThereLogDataParameter(extraParameters)) {
      Object[] extraParametersWithoutLogData = Arrays.copyOfRange(extraParameters, 1,
          extraParameters.length);
      record.setParameters(extraParametersWithoutLogData);
      result = super.formatMessage(record);
      record.setParameters(extraParameters);
    } else {
      result = super.formatMessage(record);
    }
    return result;
  }
}

代码示例来源:origin: com.sun.mail/jakarta.mail

/**
 * Formats message for the log record. This method removes any fully
 * qualified throwable class names from the message.
 *
 * @param record the log record.
 * @return the formatted message string.
 */
@Override
public String formatMessage(final LogRecord record) {
  String msg = super.formatMessage(record);
  msg = replaceClassName(msg, record.getThrown());
  msg = replaceClassName(msg, record.getParameters());
  return msg;
}

代码示例来源:origin: org.glassfish.metro/webservices-extra

/**
 * Formats message for the log record. This method removes any fully
 * qualified throwable class names from the message.
 *
 * @param record the log record.
 * @return the formatted message string.
 */
@Override
public String formatMessage(final LogRecord record) {
  String msg = super.formatMessage(record);
  msg = replaceClassName(msg, record.getThrown());
  msg = replaceClassName(msg, record.getParameters());
  return msg;
}

代码示例来源:origin: com.sun.mail/android-mail

/**
 * Formats message for the log record. This method removes any fully
 * qualified throwable class names from the message.
 *
 * @param record the log record.
 * @return the formatted message string.
 */
@Override
public String formatMessage(final LogRecord record) {
  String msg = super.formatMessage(record);
  msg = replaceClassName(msg, record.getThrown());
  msg = replaceClassName(msg, record.getParameters());
  return msg;
}

代码示例来源:origin: jboss/jboss-javaee-specs

/**
 * Formats message for the log record. This method removes any fully
 * qualified throwable class names from the message.
 *
 * @param record the log record.
 * @return the formatted message string.
 */
@Override
public String formatMessage(final LogRecord record) {
  String msg = super.formatMessage(record);
  msg = replaceClassName(msg, record.getThrown());
  msg = replaceClassName(msg, record.getParameters());
  return msg;
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

@Override
  public String toString() {
    Logger logger = Logger.getLogger(sourceClassName, bundleName);

    LogRecord record = new LogRecord(Level.INFO, messageId);

    if (cause == null) {
      record.setParameters(messageParams);

    } else {
      Object[] params = new String[1];
      params[0] = cause.toString();
      record.setParameters(params);
    }
    record.setResourceBundle(logger.getResourceBundle());
    record.setSourceClassName(sourceClassName);

    Formatter formatter = new SimpleFormatter();

    return context + " - " + formatter.formatMessage(record);
  }
}

代码示例来源:origin: blazegraph/database

public void publish(LogRecord record) {
  if(! isLoggable(record)) return;
  String formattedMessage;
  try {
    formattedMessage = getFormatter().formatMessage(record);
  } catch(Exception e) {
    reportError(null, e, ErrorManager.FORMAT_FAILURE);
    return;
  }
  log4jLogger.callAppenders
    ( new XLoggingEvent(log4jLogger, record, formattedMessage) );
}

相关文章