Log

public class Log

A class of static members used by anyone who wants to log messages.

  • An instance of the logger. It should usually be the one and only reference of the Logger protocol implementation in the system. This can be used in addition to swiftLogger, in which case log messages will be sent to both loggers.

    Declaration

    Swift

    public static var logger: Logger? { get set }
  • An instance of a swift-log Logger. If set, LoggerAPI will direct log messages to swift-log. This can be used in addition to logger, in which case log messages will be sent to both loggers.

    Declaration

    Swift

    public static var swiftLogger: Logging.Logger? { get set }
  • Log a message for use when in verbose logging mode.

    Declaration

    Swift

    public static func verbose(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file )

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Log an informational message.

    Declaration

    Swift

    public class func info(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file)

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Log a warning message.

    Declaration

    Swift

    public class func warning(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file)

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Log an error message.

    Declaration

    Swift

    public class func error(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file)

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Log a debugging message.

    Declaration

    Swift

    public class func debug(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file)

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Log a message when entering a function.

    Declaration

    Swift

    public class func entry(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file)

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Log a message when exiting a function.

    Declaration

    Swift

    public class func exit(_ msg: @autoclosure () -> String, functionName: String = #function,
        lineNum: Int = #line, fileName: String = #file)

    Parameters

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API. Defaults to the name of the function invoking this function.

    lineNum

    The line in the source code of the function invoking the logger API. Defaults to the line of the function invoking this function.

    fileName

    The file containing the source code of the function invoking the logger API. Defaults to the name of the file containing the function which invokes this function.

  • Indicates if a message with a specified type (LoggerMessageType) will be logged by some configured logger (i.e. will not be filtered out). This could be a Logger conforming to LoggerAPI, swift-log or both.

    Note that due to differences in the log levels defined by LoggerAPI and swift-log, their equivalence is mapped as follows:

       LoggerAPI:     swift-log:
       .error     ->  .error
       .warning   ->  .warning
       .info      ->  .notice
       .verbose   ->  .info
       .debug     ->  .debug
       .entry     ->  .trace
       .exit      ->  .trace
    

    For example, a swift-log Logger configured to log at the .notice level will log messages from LoggerAPI at a level of .info or higher.

    Declaration

    Swift

    public class func isLogging(_ level: LoggerMessageType) -> Bool

    Parameters

    level

    The type of message (LoggerMessageType).

    Return Value

    A Boolean indicating whether a message of the specified type (LoggerMessageType) will be logged.