BasicFormatter
public struct BasicFormatter : Formatter
Your basic, customizable log formatter
BasicFormatter does not need any setup and will automatically include all log components
It can also be given a linear sequence of log components and it will build formatted logs in that order
-
Log format sequential specification
Declaration
Swift
public let format: [LogComponent] -
Log component separator
Declaration
Swift
public let separator: String? -
Log timestamp component formatter
Declaration
Swift
public let timestampFormatter: DateFormatter -
Default timestamp component formatter
Declaration
Swift
public static var timestampFormatter: DateFormatter { get } -
Default init
Declaration
Swift
public init(_ format: [LogComponent] = LogComponent.allNonmetaComponents, separator: String = " ", timestampFormatter: DateFormatter = BasicFormatter.timestampFormatter)Parameters
_Log format specification(default:
LogComponent.allNonmetaComponents)separatorLog component separator (default: “ ”)
timestampFormatterLog timestamp component formatter (default:
BasicFormatter.timestampFormatter) -
Our main log formatting method
Declaration
Swift
public func processLog(level: Logger.Level, message: Logger.Message, prettyMetadata: String?, file: String, function: String, line: UInt) -> StringParameters
levellog level
messageactual message
prettyMetadataoptional metadata that has already been
prettified
filelog’s originating file
functionlog’s originating function
linelog’s originating line
Return Value
Result of formatting the log
-
apple/swift-log‘s log format
{timestamp} {level}: {message}Example:
2019-07-30T13:49:07-0400 error: Test error messageDeclaration
Swift
public static let apple: BasicFormatter -
Adorkable’s go-to log format 😘
{timestamp} â–¶ {level} â–¶ {file}:{line} â–¶ {function} â–¶ {message} â–¶ {metadata}Example:
2019-07-30T13:49:07-0400 â–¶ error â–¶ /asdf/swift-log-format-and-pipe/Tests/LoggingFormatAndPipeTests/FormatterTests.swift:25 â–¶ testFormatter(_:) â–¶ Test error messageDeclaration
Swift
public static let adorkable: BasicFormatter
View on GitHub
BasicFormatter Structure Reference