FieldBasedLogFormatter
open class FieldBasedLogFormatter: ConcatenatingLogFormatter
The FieldBasedLogFormatter provides a simple interface for constructing
a customized LogFormatter by specifying different fields.
Let’s say you wanted to construct a LogFormatter that outputs the following
fields separated by tabs:
- The
LogEntry‘stimestampproperty as a UNIX time value - The
severityof theLogEntryas a numeric value - The
Payloadof theLogEntry
You could do this by constructing a FieldBasedLogFormatter as follows:
let formatter = FieldBasedLogFormatter(fields: [.timestamp(.unix),
.delimiter(.tab),
.severity(.numeric),
.delimiter(.tab),
.payload])
-
The individual
See moreFielddeclarations for theFieldBasedLogFormatter.Declaration
Swift
public enum Field -
Initializes the
FieldBasedLogFormatterto use the specified fields.Declaration
Swift
public init(fields: [Field], hardFail: Bool = false)Parameters
fieldsThe
Fields that will be used by the receiver.hardFailDetermines the behavior of
format(_:)when one of the receiver’sformattersreturnsnil. Whenfalse, if any formatter returnsnil, it is simply excluded from the concatenation, but formatting continues. Unless none of theformattersreturns a string, the receiver will always return a non-nilvalue. However, whenhardFailistrue, all of theformattersmust return strings; if any formatter returnsnil, the receiver also returnsnil. -
Initializes the
FieldBasedLogFormatterto use the specified formatters.Declaration
Swift
public override init(formatters: [LogFormatter], hardFail: Bool = false)Parameters
formattersThe
LogFormatters that will be used by the receiver.hardFailDetermines the behavior of
format(_:)when one of the receiver’sformattersreturnsnil. Whenfalse, if any formatter returnsnil, it is simply excluded from the concatenation, but formatting continues. Unless none of theformattersreturns a string, the receiver will always return a non-nilvalue. However, whenhardFailistrue, all of theformattersmust return strings; if any formatter returnsnil, the receiver also returnsnil.
View on GitHub
FieldBasedLogFormatter Class Reference