Classes
The following classes are available globally.
-
A
LogFormatter
configured to be ideal for writing human-readable log files.By default, this formatter:
- Uses
.default
as theTimestampStyle
- Uses a custom
SeverityStyle
that pads the capitalized severity name - Uses
.hex
as theCallingThreadStyle
- Uses default field separator delimiters
- Outputs the source code filename and line number of the call site
Each of these settings can be overridden during instantiation.
See moreDeclaration
Swift
open class ReadableLogFormatter: StandardLogFormatter
- Uses
-
A
See moreLogFormatter
that outputs Xcode-bound trace information for eachLogEntry
that has aPayload
of.trace
.Declaration
Swift
public final class XcodeTraceLogFormatter: FieldBasedLogFormatter
-
A
See moreLogConfiguration
optimized for use when running within Xcode.Declaration
Swift
open class XcodeLogConfiguration: ConsoleLogConfiguration
-
A
LogRecorder
implementation that maintains a set of daily rotating log files, kept for a user-specified number of days.Important
ARotatingLogFileRecorder
instance assumes full control over the log directory specified by itsdirectoryPath
property. Please see the initializer documentation for details.Declaration
Swift
open class RotatingLogFileRecorder: LogRecorderBase
-
The
See moreStandardOutputLogRecorder
is anOutputStreamLogRecorder
that writes log messages to the standard output stream (`stdout`
) of the running process.Declaration
Swift
open class StandardOutputLogRecorder: OutputStreamLogRecorder
-
A
See moreLogConfiguration
that uses an underlyingRotatingLogFileRecorder
to maintain a directory of log files that are rotated on a daily basis.Declaration
Swift
open class RotatingLogFileConfiguration: BasicLogConfiguration
-
The
See moreOutputStreamLogRecorder
logs messages by writing to the standard output stream of the running process.Declaration
Swift
open class OutputStreamLogRecorder: LogRecorderBase
-
In case the name didn’t give it away, the
See moreBasicLogConfiguration
class provides a basic implementation of theLogConfiguration
protocol.Declaration
Swift
open class BasicLogConfiguration: LogConfiguration
-
The
BufferedLogRecorder
is a genericLogRecorder
that buffers the log messages passed to itsrecord()
function.Construction requires a
createBufferItem
function, which is responsible for converting theLogEntry
and formatted messageString
into the genericBufferItem
type.Three specific subclasses are also provided which will buffer a different
BufferItem
type for each call torecord()
:BufferedMessageRecorder
storesString
s containing the formatted log message.BufferedLogEntryRecorder
stores theLogEntry
values passed torecord()
.BufferedLogEntryMessageRecorder
stores a(LogEntry, String)
tuple containing theLogEntry
and formatted log message.
Declaration
Swift
open class BufferedLogRecorder<BufferItem>: LogRecorderBase
-
The
See moreBufferedMessageRecorder
buffers the formatted log messages passed to itsrecord()
function.Declaration
Swift
open class BufferedMessageRecorder: BufferedLogRecorder<String>
-
Declaration
Swift
open class BufferedLogEntryRecorder: BufferedLogRecorder<LogEntry>
-
The
See moreBufferedLogEntryMessageRecorder
buffers eachLogEntry
and formatted message passed to itsrecord()
function.Declaration
Swift
open class BufferedLogEntryMessageRecorder: BufferedLogRecorder<(LogEntry, String)>
-
A
LogRecorder
implementation that appends log entries to a file.Note
FileLogRecorder
is a simple log appender that provides no mechanism for file rotation or truncation. Unless you manually manage the log file when aFileLogRecorder
doesn’t have it open, you will end up with an ever-growing file. Use aRotatingLogFileRecorder
instead if you’d rather not have to concern yourself with such details.Declaration
Swift
open class FileLogRecorder: LogRecorderBase
-
The
FieldBasedLogFormatter
provides a simple interface for constructing a customizedLogFormatter
by specifying different fields.Let’s say you wanted to construct a
LogFormatter
that outputs the following fields separated by tabs:- The
LogEntry
‘stimestamp
property as a UNIX time value - The
severity
of theLogEntry
as a numeric value - The
Payload
of theLogEntry
You could do this by constructing a
FieldBasedLogFormatter
as follows:
See morelet formatter = FieldBasedLogFormatter(fields: [.timestamp(.unix), .delimiter(.tab), .severity(.numeric), .delimiter(.tab), .payload])
Declaration
Swift
open class FieldBasedLogFormatter: ConcatenatingLogFormatter
- The
-
LogReceptacle
s provide the low-level interface for accepting log messages.Although you could use a
See moreLogReceptacle
directly to perform all logging functions, theLog
implementation provides a higher-level interface that’s more convenient to use within your code.Declaration
Swift
public final class LogReceptacle
-
The
See moreConcatenatingLogFormatter
lets you combine the output of multipleLogFormatter
s by concatenating their output and returning the result.Declaration
Swift
open class ConcatenatingLogFormatter: LogFormatter
-
A standard
LogConfiguration
that, by default, uses theos_log()
function (via theOSLogRecorder
), which is only available as of iOS 10.0, macOS 10.12, tvOS 10.0, and watchOS 3.0.If
See moreos_log()
is not available, or if theStandardLogConfiguration
is configured to bypass it, log messages will be written to either thestdout
orstderr
output stream of the running process.Declaration
Swift
open class ConsoleLogConfiguration: BasicLogConfiguration
-
The
StandardStreamsLogRecorder
is aLogRecorder
that writes log messages to either the standard output stream (`stdout`
) or the standard error stream (`stderr`
) of the running process.Messages are directed to the appropriate stream depending on the
severity
property of theLogEntry
being recorded.Messages having a severity of
See more.verbose
,.debug
and.info
will be directed tostdout
, while those with a severity of.warning
and.error
are directed tostderr
.Declaration
Swift
open class StandardStreamsLogRecorder: LogRecorderBase
-
A partial implementation of the
See moreLogRecorder
protocol.Declaration
Swift
open class LogRecorderBase: LogRecorder
-
The
See moreStandardErrorLogRecorder
is anOutputStreamLogRecorder
that writes log messages to the standard error stream (`stderr`
) of the running process.Declaration
Swift
open class StandardErrorLogRecorder: OutputStreamLogRecorder
-
A standard
See moreLogFormatter
that provides some common customization points.Declaration
Swift
open class StandardLogFormatter: FieldBasedLogFormatter
-
A
LogFormatter
configured to be ideal for writing machine-parsable log files.By default, this formatter:
- Uses
.unix
as theTimestampStyle
- Uses
.numeric
as theSeverityStyle
- Uses
.hex
as theCallingThreadStyle
- Uses
.tab
as theDelimiterStyle
- Outputs the source code filename and line number of the call site
Each of these settings can be overridden during instantiation.
See moreDeclaration
Swift
open class ParsableLogFormatter: StandardLogFormatter
- Uses
-
A
See moreLogFormatter
ideal for use within Xcode. This format is not well-suited for parsing.Declaration
Swift
public final class XcodeLogFormatter: LogFormatter