Writer

public protocol Writer

The Writer protocol defines the interface required when writing a log writer for the TraceLog system. Log writers are used to output all log messages to an output device like stdout, http endpoint, tcp/ip sockets, etc.

There are no constructor/init requirements so any init method can be defined in your writer to initialize it prior to passing it to TraceLog.

ConsoleWriter is a concrete implementation of the Writer protocol and can be used as a basic example of creating custom writers.

See also

ConsoleWriter for an example implementation.

See also

FileWriter for an example implementation.
  • Called when the logger needs to log an event to this logger.

    See also

    LogEntry for complete attribute details.

    Declaration

    Swift

    func write(_ entry: LogEntry) -> Result<Int, FailureReason>

    Parameters

    entry

    A LogEntry type to write to the output.

    Return Value

    An Int indicating the actual number of bytes written to the output after conversion of the LogEntry. This is the actual number of bytes (after any encoding) not the number of visible characters.

  • Log Entry represents an element that can be written by a Writer.

    See also

    LogLevel for logging level constants.

    See also

    RuntimeContext for details on the runtime context attributes available.

    See also

    StaticContext for details on the static context attributes available.

    Declaration

    Swift

    typealias LogEntry = (timestamp: Double, level: LogLevel, tag: String, message: String, runtimeContext: RuntimeContext, staticContext: StaticContext)

    Parameters

    timestamp

    Timestamp of the log event (number of seconds from 1970).

    level

    The LogLevel of this logging event. Note: log will not be called if the LegLevel is not set to above this calls log level

    tag

    The tag associated with the log event.

    message

    The message string (already formatted) for this logging event.

    file

    The source file (of the calling program) of this logging event.

    runtimeContext

    An object containing information about the state of the runtime such as thread ID (SeeAlso: RuntimeContext)

    staticContext

    An object containing the static information at the time of the func call such as function name and line number (SeeAlso: StaticContext)

    Return Value

    LogResult indicating the result of the attempt to log the statement to the endpoint.