Class SyslogLayout
- java.lang.Object
-
- org.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
- org.apache.logging.log4j.core.layout.AbstractStringLayout
-
- org.apache.logging.log4j.core.layout.SyslogLayout
-
- All Implemented Interfaces:
LocationAware
,Layout<java.lang.String>
,Encoder<LogEvent>
,StringLayout
@Plugin(name="SyslogLayout", category="Core", elementType="layout", printObject=true) public final class SyslogLayout extends AbstractStringLayout
Formats a log event as a BSD Log record.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SyslogLayout.Builder<B extends SyslogLayout.Builder<B>>
Builds a SyslogLayout.-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.SimpleDateFormat
dateFormat
Date format used if header = true.private java.lang.String
escapeNewLine
private Facility
facility
private boolean
includeNewLine
private java.lang.String
localHostname
Host name used to identify messages from this appender.static java.util.regex.Pattern
NEWLINE_PATTERN
Match newlines in a platform-independent manner.-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE
-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGER
-
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SyslogLayout(Facility facility, boolean includeNL, java.lang.String escapeNL, java.nio.charset.Charset charset)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
addDate(long timestamp, java.lang.StringBuilder buf)
static SyslogLayout
createLayout(Facility facility, boolean includeNewLine, java.lang.String escapeNL, java.nio.charset.Charset charset)
Deprecated.UsenewBuilder()
.java.util.Map<java.lang.String,java.lang.String>
getContentFormat()
Gets this SyslogLayout's content format.Facility
getFacility()
Gets the facility.static <B extends SyslogLayout.Builder<B>>
BnewBuilder()
java.lang.String
toSerializable(LogEvent event)
Formats aLogEvent
in conformance with the BSD Log record format.-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getContentType, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, requiresLocation, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
encode, getConfiguration, markEvent
-
-
-
-
Field Detail
-
NEWLINE_PATTERN
public static final java.util.regex.Pattern NEWLINE_PATTERN
Match newlines in a platform-independent manner.
-
facility
private final Facility facility
-
includeNewLine
private final boolean includeNewLine
-
escapeNewLine
private final java.lang.String escapeNewLine
-
dateFormat
private final java.text.SimpleDateFormat dateFormat
Date format used if header = true.
-
localHostname
private final java.lang.String localHostname
Host name used to identify messages from this appender.
-
-
Constructor Detail
-
SyslogLayout
protected SyslogLayout(Facility facility, boolean includeNL, java.lang.String escapeNL, java.nio.charset.Charset charset)
-
-
Method Detail
-
newBuilder
@PluginBuilderFactory public static <B extends SyslogLayout.Builder<B>> B newBuilder()
-
toSerializable
public java.lang.String toSerializable(LogEvent event)
Formats aLogEvent
in conformance with the BSD Log record format.- Parameters:
event
- The LogEvent- Returns:
- the event formatted as a String.
-
addDate
private void addDate(long timestamp, java.lang.StringBuilder buf)
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
Gets this SyslogLayout's content format. Specified by:- Key: "structured" Value: "false"
- Key: "dateFormat" Value: "MMM dd HH:mm:ss"
- Key: "format" Value: "<LEVEL>TIMESTAMP PROP(HOSTNAME) MESSAGE"
- Key: "formatType" Value: "logfilepatternreceiver" (format uses the keywords supported by LogFilePatternReceiver)
- Specified by:
getContentFormat
in interfaceLayout<java.lang.String>
- Overrides:
getContentFormat
in classAbstractLayout<java.lang.String>
- Returns:
- Map of content format keys supporting SyslogLayout
-
createLayout
@Deprecated public static SyslogLayout createLayout(Facility facility, boolean includeNewLine, java.lang.String escapeNL, java.nio.charset.Charset charset)
Deprecated.UsenewBuilder()
.Creates a SyslogLayout.- Parameters:
facility
- The Facility is used to try to classify the message.includeNewLine
- If true a newline will be appended to the result.escapeNL
- Pattern to use for replacing newlines.charset
- The character set.- Returns:
- A SyslogLayout.
-
getFacility
public Facility getFacility()
Gets the facility.- Returns:
- the facility
-
-