org.apache.logging.log4j.message.Message.getParameters()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(111)

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

Message.getParameters介绍

[英]Gets parameter values, if any.
[中]获取参数值(如果有)。

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Override
public Object[] getParameters() {
  if (message != null) {
    return message.getParameters();
  }
  return null;
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

sb.append(SPACE);
sb.append(msg.getFormattedMessage());
final Object[] params = msg.getParameters();
Throwable t;
if (throwable == null && params != null && params[params.length - 1] instanceof Throwable) {

代码示例来源:origin: org.apache.logging.log4j/log4j-api

final Object[] params = msg.getParameters();
Throwable t;
if (throwable == null && params != null && params.length > 0

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Override
  public void format(final LogEvent event, final StringBuilder toAppendTo) {
    toAppendTo.append('[');
    Object[] parameters = event.getMessage().getParameters();
    if (parameters != null) {
      for (int i = 0; i < parameters.length; i++) {
        StringBuilders.appendValue(toAppendTo, parameters[i]);
        if (i != parameters.length - 1) {
          toAppendTo.append(',');
        }
      }
    }
    toAppendTo.append(']');
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

sb.append(' ');
final Object[] params = msg.getParameters();
Throwable t;
if (throwable == null && params != null && params.length > 0 && params[params.length - 1] instanceof Throwable) {

代码示例来源: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

@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

assertEquals("format", "msg in a {}", memento.getFormat());
assertEquals("formatted", "msg in a bottle", memento.getFormattedMessage());
assertEquals("parameters", new String[] {"bottle"}, memento.getParameters());
assertEquals("parameters", new String[] {"bottle"}, eventMementoMessage.getParameters());
assertEquals("parameters", new String[] {"bottle"}, log4JLogEventMessage.getParameters());

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Object[] getParameters() {
  if (message != null) {
    return message.getParameters();
  }
  return null;
}

代码示例来源:origin: SAP/cf-java-logging-support

@Override
  public void format(LogEvent event, StringBuilder toAppendTo) {
    converter.convert(event.getMessage().getParameters(), toAppendTo);
  }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

sb.append(SPACE);
sb.append(msg.getFormattedMessage());
final Object[] params = msg.getParameters();
Throwable t;
if (throwable == null && params != null && params[params.length - 1] instanceof Throwable) {

代码示例来源:origin: ops4j/org.ops4j.pax.logging

final Object[] params = msg.getParameters();
Throwable t;
if (throwable == null && params != null && params.length > 0

代码示例来源:origin: org.apache.logging.log4j.adapters/log4j-to-slf4j

data.getParameters(), t);
} else {
  switch (level) {
    case DEBUG :
      logger.debug(getMarker(marker), data.getFormattedMessage(), data.getParameters(), t);
      break;
    case TRACE :
      logger.trace(getMarker(marker), data.getFormattedMessage(), data.getParameters(), t);
      break;
    case INFO :
      logger.info(getMarker(marker), data.getFormattedMessage(), data.getParameters(), t);
      break;
    case WARN :
      logger.warn(getMarker(marker), data.getFormattedMessage(), data.getParameters(), t);
      break;
    case ERROR :
      logger.error(getMarker(marker), data.getFormattedMessage(), data.getParameters(), t);
      break;
    default :
      logger.error(getMarker(marker), data.getFormattedMessage(), data.getParameters(), t);
      break;

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public String toSerializable(final LogEvent event) {
  final Message message = event.getMessage();
  final Object[] parameters = message.getParameters();
  final StringBuilder buffer = getStringBuilder();
  try {
    getFormat().printRecord(buffer, parameters);
    return buffer.toString();
  } catch (final IOException e) {
    StatusLogger.getLogger().error(message, e);
    return getFormat().getCommentMarker() + " " + e;
  }
}

代码示例来源:origin: com.getsentry.raven/raven-log4j2

eventBuilder.withSentryInterface(new MessageInterface(
  eventMessage.getFormat(),
  formatMessageParameters(eventMessage.getParameters()),
  eventMessage.getFormattedMessage()));

代码示例来源:origin: io.sentry/sentry-log4j2

eventBuilder.withSentryInterface(new MessageInterface(
  eventMessage.getFormat(),
  formatMessageParameters(eventMessage.getParameters()),
  eventMessage.getFormattedMessage()));

代码示例来源:origin: javabeanz/owasp-security-logging

Object[] params = msg.getParameters();
if (params == null || params.length == 0) {
  return source;

相关文章