HeliumLogger

public class HeliumLogger

A lightweight implementation of the LoggerAPI protocol.

  • A Boolean value that indicates whether the logger output should be colorized.

    Usage Example:

    The logger is set up to log verbose level messages (this is the default) and all levels below, that is, it will show messages of type verbose, info, warning and error.

    let logger = HeliumLogger()
    logger.colored = true
    Log.logger = logger
    Log.error("This message will be red when your application is run in the terminal.")
    

    Declaration

    Swift

    public var colored: Bool = false
  • A Boolean value indicating whether to use the detailed logging format when a user logging format is not specified.

    Declaration

    Swift

    public var details: Bool = true
  • A Boolean value indicating whether to use the full file path, or just the filename.

    Declaration

    Swift

    public var fullFilePath: Bool = false
  • The user specified logging format, if format is not nil.

    For example: [(%date)] [(%type)] [(%file):(%line) (%func)] (%msg).

    Declaration

    Swift

    public var format: String?
  • The format used when adding the date and time to logged messages, if dateFormat is not nil.

    Declaration

    Swift

    public var dateFormat: String?
  • The timezone used in the date time format, if timeZone is not nil.

    Declaration

    Swift

    public var timeZone: TimeZone?
  • Default date format - ISO 8601.

    Declaration

    Swift

    public static let defaultDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
  • Create a HeliumLogger instance and set it up as the logger used by the LoggerAPI protocol.

    Usage Example:

    In the default case, the logger is set up to log verbose level messages and all levels below, that is, it will show messages of type verbose, info, warning and error.

    HeliumLogger.use()
    

    In the following example, the logger is set up to log warning level messages and all levels below, i.e. it will show messages of type warning and error.

    HeliumLogger.use(.warning)
    

    Declaration

    Swift

    public class func use(_ type: LoggerMessageType = .verbose)

    Parameters

    type

    The most detailed message type (LoggerMessageType) to see in the output of the logger. Defaults to verbose.

  • Create a HeliumLogger instance.

    Declaration

    Swift

    public init (_ type: LoggerMessageType = .verbose)

    Parameters

    type

    The most detailed message type (LoggerMessageType) to see in the output of the logger. Defaults to verbose.

  • Output a logged message.

    Declaration

    Swift

    public func log(_ type: LoggerMessageType, msg: String,
                    functionName: String, lineNum: Int, fileName: String )

    Parameters

    type

    The type of the message (LoggerMessageType) being logged.

    msg

    The message to be logged.

    functionName

    The name of the function invoking the logger API.

    lineNum

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

    fileName

    The file containing the source code of the function invoking the logger API.

  • Indicates if a message with a specified type (LoggerMessageType) will be in the logger output (i.e. will not be filtered out).

    Usage Example:

    The logger is set up to log warning level messages and all levels below, that is, it will show messages of type warning and error. This means a verbose level message will not be displayed.

    let logger = HeliumLogger(.warning)
    Log.logger = logger
    logger.isLogging(.warning) // Returns true
    logger.isLogging(.verbose) // Returns false
    

    Declaration

    Swift

    public func isLogging(_ type: LoggerMessageType) -> Bool

    Parameters

    type

    The type of message (LoggerMessageType).

    Return Value

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