org.apache.logging.log4j.core.util.StringBuilderWriter Java Examples

The following examples show how to use org.apache.logging.log4j.core.util.StringBuilderWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThrowablePatternConverter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private void formatOption(final Throwable throwable, final String suffix, final StringBuilder buffer) {
    final int len = buffer.length();
    if (len > 0 && !Character.isWhitespace(buffer.charAt(len - 1))) {
        buffer.append(' ');
    }
    if (!options.allLines() || nonStandardLineSeparator || Strings.isNotBlank(suffix)) {
        final StringWriter w = new StringWriter();
        throwable.printStackTrace(new PrintWriter(w));

        final String[] array = w.toString().split(Strings.LINE_SEPARATOR);
        final int limit = options.minLines(array.length) - 1;
        final boolean suffixNotBlank = Strings.isNotBlank(suffix);
        for (int i = 0; i <= limit; ++i) {
            buffer.append(array[i]);
            if (suffixNotBlank) {
                buffer.append(' ');
                buffer.append(suffix);
            }
            if (i < limit) {
                buffer.append(options.getSeparator());
            }
        }
    } else {
        throwable.printStackTrace(new PrintWriter(new StringBuilderWriter(buffer)));
    }
}
 
Example #2
Source File: ObjectMessageJacksonSerializer.java    From ecs-logging-java with Apache License 2.0 5 votes vote down vote up
@Override
public void formatTo(StringBuilder buffer, ObjectMessage objectMessage) {
    try {
        objectMapper.writeValue(new StringBuilderWriter(buffer), objectMessage.getParameter());
    } catch (IOException e) {
        StatusLogger.getLogger().catching(e);
        objectMessage.formatTo(buffer);
    }
}
 
Example #3
Source File: AbstractJacksonLayout.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public String toSerializable(final LogEvent event) {
    final StringBuilderWriter writer = new StringBuilderWriter();
    try {
        toSerializable(event, writer);
        return writer.toString();
    } catch (final IOException e) {
        LOGGER.error(e);
        return Strings.EMPTY;
    }
}
 
Example #4
Source File: AbstractJacksonLayout.java    From curiostack with MIT License 5 votes vote down vote up
/**
 * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
 *
 * @param event The LogEvent.
 * @return The XML representation of the LogEvent.
 */
@Override
public String toSerializable(final LogEvent event) {
  try (final StringBuilderWriter writer = new StringBuilderWriter()) {
    toSerializable(event, writer);
    return writer.toString();
  } catch (final IOException e) {
    // Should this be an ISE or IAE?
    LOGGER.error(e);
    return Strings.EMPTY;
  }
}
 
Example #5
Source File: AbstractJacksonLayout.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
 *
 * @param event
 *            The LogEvent.
 * @return The XML representation of the LogEvent.
 */
@Override
public String toSerializable(final LogEvent event) {
    try (final StringBuilderWriter writer = new StringBuilderWriter()) {
        toSerializable(event, writer);
        return writer.toString();
    } catch (final IOException e) {
        // Should this be an ISE or IAE?
        LOGGER.error(e);
        return Strings.EMPTY;
    }
}
 
Example #6
Source File: AbstractJacksonLayout.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
 *
 * @param event
 *            The LogEvent.
 * @return The XML representation of the LogEvent.
 */
@Override
public String toSerializable(final LogEvent event) {
    final StringBuilderWriter writer = new StringBuilderWriter();
    try {
        toSerializable(event, writer);
        return writer.toString();
    } catch (final IOException e) {
        // Should this be an ISE or IAE?
        LOGGER.error(e);
        return Strings.EMPTY;
    }
}