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

The following examples show how to use org.apache.logging.log4j.core.layout.SerializedLayout. 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: AdvancedKafkaAppender.java    From summerframework with 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 File: PulsarAppender.java    From pulsar with 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 File: RocketmqLog4j2Appender.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example #4
Source File: RocketmqLog4j2Appender.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example #5
Source File: RocketmqLog4j2Appender.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example #6
Source File: RocketmqLog4j2Appender.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example #7
Source File: RocketmqLog4j2Appender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}
 
Example #8
Source File: RocketmqLog4j2Appender.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private Builder() {
    this.layout = SerializedLayout.createLayout();
    this.ignoreExceptions = true;
}