Logger

@objc open class Logger: NSObject, LogWriter

Provides Logging support for the SDK using the Apple Unified Logging API

  • Specifies the default logging level to be used if no logging level configuration is found.

    Declaration

    Swift

    public static var defaultLoggingLevel: LoggerLevel = .info
  • Specifies the configuration key (as in a key/value pair) used to determine the logging level in either the info.plist or the settings bundle root.plist

    Default: logging_level

    Declaration

    Swift

    public static var loggingLevelConfigKey = "logging_level"
  • Specifies where the logging level configuration key/value should be found.

    Default: Settings

    If the configuration location is Settings, an observer will be created to monitor for changes to the current value and automatically update the loggingLevel as Settings changes.

    Declaration

    Swift

    public static var loggingLevelConfigLocation = ConfigurationLocation.settings
  • Shared instance of the Logger class Will initialize to a Logger object, but is replaceable with any class implementing the LogWriter protocol.

    Declaration

    Swift

    public static var shared: LogWriter = Logger()
  • Optional closure, when set is called instead of write(logEntry: for:) method to write a message to the log.

    It is safe to call write(logEntry: for:) from within this closure.

    Declaration

    Swift

    public var writeLogEntry: ((_ writer: LogWriter, _ logEntry: String, _ level: LoggerLevel) -> Void)?

    Parameters

    writer

    This LogWriter logger

    logEntry

    The string to write to the log

    level

    The LoggerLevel of this log entry

  • Writes a log entry for the specified level to the Apple Unified Logging API

    Declaration

    Swift

    open func write(logEntry message: String, for level: LoggerLevel)
  • Initializes a new logger object

    This Logger will automatically attempt to load it’s inital logging level setting from configuration according to the Logger.loggingLevelConfigLocation and Logger.loggingLevelConfigKey values.

    If no configured value is found, the Logger.defaultLoggingLevel setting will be used.

    If the configuration location is Settings, an observer will be created to monitor for changes to the current value and automatically update the loggingLevel as Settings changes.

    Declaration

    Swift

    public override init()
  • Initializes a new logger object set to the specified logging level

    Declaration

    Swift

    public init(loggingLevel: LoggerLevel)
  • Sets and gets the current logger verbosity level. Logs more verbose than this level will not be output to the logging system.

    For example:

    If the loggerLevel is set to LoggerLevel.info, then:

    Logger.shared.loggerlevel = LoggerLevel.info

    Logger.warn("this will be output")

    Logger.info("this will be output")

    Logger.debug("this will not be output")

    Logger.trace("this will not be output")

    Declaration

    Swift

    open var loggerLevel: LoggerLevel
  • Return true if the log level will output trace level messages.

    Declaration

    Swift

    open func isTraceEnabled() -> Bool
  • log a trace message.

    Declaration

    Swift

    open func trace(_ log: String)
  • Return true if the log level will output debug level messages.

    Declaration

    Swift

    open func isDebugEnabled() -> Bool
  • log a debug message.

    Declaration

    Swift

    open func debug(_ log: String)
  • Return true if the log level will output info level messages.

    Declaration

    Swift

    open func isInfoEnabled() -> Bool
  • log a info message.

    Declaration

    Swift

    open func info(_ log: String)
  • Return true if the log level will output warning level messages.

    Declaration

    Swift

    open func isWarnEnabled() -> Bool
  • log a warning message.

    Declaration

    Swift

    open func warn(_ log: String)
  • Return true if the log level will output error level messages.

    Declaration

    Swift

    open func isErrorEnabled() -> Bool
  • log a error message.

    Declaration

    Swift

    open func error(_ log: String)
  • Return true if the log level will output fatal level messages.

    Declaration

    Swift

    open func isFatalEnabled() -> Bool
  • log a fatal message.

    Declaration

    Swift

    open func fatal(_ log: String)
  • Return true if logging is disabled and nothing will be logged.

    Declaration

    Swift

    open func isLoggingOff() -> Bool
  • Shortcut to shared logger: Sets and gets the current logger verbosity level.

    Declaration

    Swift

    public static var loggerLevel: LoggerLevel
  • Shortcut to shared logger: Return true if the log level will output trace level messages.

    Declaration

    Swift

    public static func isTraceEnabled() -> Bool
  • Shortcut to shared logger: log a trace message.

    Declaration

    Swift

    public static func trace(_ log: String)
  • Shortcut to shared logger: Return true if the log level will output debug level messages.

    Declaration

    Swift

    public static func isDebugEnabled() -> Bool
  • Shortcut to shared logger: log a debug message.

    Declaration

    Swift

    public static func debug(_ log: String)
  • Shortcut to shared logger: Return true if the log level will output info level messages.

    Declaration

    Swift

    public static func isInfoEnabled() -> Bool
  • Shortcut to shared logger: log a info message.

    Declaration

    Swift

    public static func info(_ log: String)
  • Shortcut to shared logger: Return true if the log level will output warning level messages.

    Declaration

    Swift

    public static func isWarnEnabled() -> Bool
  • Shortcut to shared logger: log a warning message.

    Declaration

    Swift

    public static func warn(_ log: String)
  • Shortcut to shared logger: Return true if the log level will output error level messages.

    Declaration

    Swift

    public static func isErrorEnabled() -> Bool
  • Shortcut to shared logger: log a error message.

    Declaration

    Swift

    public static func error(_ log: String)
  • Shortcut to shared logger: Return true if the log level will output fatal level messages.

    Declaration

    Swift

    public static func isFatalEnabled() -> Bool
  • Shortcut to shared logger: log a fatal message.

    Declaration

    Swift

    public static func fatal(_ log: String)
  • Shortcut to shared logger: Return true if logging is disabled and nothing will be logged.

    Declaration

    Swift

    public static func isLoggingOff() -> Bool