Java Code Examples for org.apache.logging.log4j.core.layout.SerializedLayout

The following examples show how to use org.apache.logging.log4j.core.layout.SerializedLayout. These examples are extracted from open source projects. 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 Project: summerframework   Source File: AdvancedKafkaAppender.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void append(final LogEvent event) {
    try {
        final Layout<? extends Serializable> layout = getLayout();
        byte[] data;
        if (layout != null) {
            if (layout instanceof SerializedLayout) {
                final byte[] header = layout.getHeader();
                final byte[] body = layout.toByteArray(event);
                data = new byte[header.length + body.length];
                System.arraycopy(header, 0, data, 0, header.length);
                System.arraycopy(body, 0, data, header.length, body.length);
            } else {
                data = layout.toByteArray(event);
            }
        } else {
            data = StringEncoder.toBytes(event.getMessage().getFormattedMessage(), StandardCharsets.UTF_8);
        }
        manager.send(topic, data);
    } catch (final Exception e) {
        LOGGER.error("Unable to write to Kafka [{}] for appender [{}].", manager.getName(), getName(), e);
        throw new AppenderLoggingException("Unable to write to Kafka in appender: " + e.getMessage(), e);
    }
}
 
Example 2
Source Project: pulsar   Source File: PulsarAppender.java    License: Apache License 2.0 5 votes vote down vote up
private void tryAppend(final LogEvent event) {
    final Layout<? extends Serializable> layout = getLayout();
    byte[] data;
    if (layout instanceof SerializedLayout) {
        final byte[] header = layout.getHeader();
        final byte[] body = layout.toByteArray(event);
        data = new byte[header.length + body.length];
        System.arraycopy(header, 0, data, 0, header.length);
        System.arraycopy(body, 0, data, header.length, body.length);
    } else {
        data = layout.toByteArray(event);
    }
    manager.send(data);
}
 
Example 3
Source Project: DDMQ   Source File: RocketmqLog4j2Appender.java    License: Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example 4
Source Project: rocketmq-4.3.0   Source File: RocketmqLog4j2Appender.java    License: Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example 5
Source Project: rocketmq-read   Source File: RocketmqLog4j2Appender.java    License: Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example 6
Source Project: DDMQ   Source File: RocketmqLog4j2Appender.java    License: Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example 7
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example 8
Source Project: rocketmq   Source File: RocketmqLog4j2Appender.java    License: Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}