Java Code Examples for org.apache.logging.log4j.core.Layout#getHeader()
The following examples show how to use
org.apache.logging.log4j.core.Layout#getHeader() .
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 |
@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 |
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: ListAppender.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public ListAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout, final boolean newline, final boolean raw) { super(name, filter, layout, true, Property.EMPTY_ARRAY); this.newLine = newline; this.raw = raw; if (layout != null) { final byte[] bytes = layout.getHeader(); if (bytes != null) { write(bytes); } } }
Example 4
Source File: SmtpManager.java From logging-log4j2 with Apache License 2.0 | 4 votes |
protected void writeHeader(final Layout<?> layout, final OutputStream out) throws IOException { final byte[] header = layout.getHeader(); if (header != null) { out.write(header); } }