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
  • 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
  • A Boolean value indicating whether to include SwiftLog metadata in the logging format when a user logging format is not specified.

    Declaration

    Swift

    public var includeMetadata: Bool
  • A Boolean value indicating whether to include SwiftLog label in the logging format when a user logging format is not specified.

    Declaration

    Swift

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

    Declaration

    Swift

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

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public var timeZone: TimeZone? { get set }
  • Default date format - ISO 8601.

    Declaration

    Swift

    public static let defaultDateFormat: String
  • 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.

  • A one-time configuration function to bootstrap the SwiftLog logging system using HeliumLogger as the logging backend.

    Usage Example:

    This bootstraps the SwiftLog logging system with a default HeliumLogger instance. The default HeliumLogger instance will be used as the logging backend for SwiftLog.

    HeliumLogger.bootstrapSwiftLog()
    

    It’s also possible to customize the default HeliumLogger instance using a configuration closure.

    HeliumLogger.bootstrapSwiftLog { heliumLogger in
        heliumLogger.colored = true
    }
    

    Declaration

    Swift

    public static func bootstrapSwiftLog(_ configure: ((HeliumLogger) -> Void)? = nil)

    Parameters

    configure

    An optional closure that may be used to configure the default HeliumLogger instance.

  • Creates a HeliumLogHandler instance for use with the SwiftLog logging system.

    Usage Example:

    This may be used to bootstrap the SwiftLog logging system with a HeliumLogger instance. The HeliumLogger instance will be used as the logging backend for SwiftLog.

    let heliumLogger = HeliumLogger()
    LoggingSystem.bootstrap(heliumLogger.makeLogHandler)
    

    Declaration

    Swift

    public func makeLogHandler(label: String) -> HeliumLogHandler

    Parameters

    label

    The label to use for a SwiftLog Logger.

  • Creates a HeliumLogHandler instance for use with the SwiftLog logging system.

    Usage Example:

    This may be used to bootstrap the SwiftLog logging system with a default HeliumLogger instance. The default HeliumLogger instance will be used as the logging backend for SwiftLog.

    LoggingSystem.bootstrap(HeliumLogger.makeLogHandler)
    

    Declaration

    Swift

    public static func makeLogHandler(label: String) -> HeliumLogHandler

    Parameters

    label

    The label to use for a SwiftLog Logger.

  • 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.