Lock.swift: Logging

Lock provides options to easily turn on and off logging capabilities, as well as adjust other logging related settings.

logLevel

By default this is .off, Syslog logging levels are supported.

.withOptions {
  $0.logLevel = .all
}

Was this helpful?

/

logHttpRequest

This option allows you to choose whether or not to log Auth0.swift API requests. By default this is false.

.withOptions {
  $0.logHttpRequest = true
}

Was this helpful?

/

loggerOutput

You can specify a logger output handler, by default this uses the print statement.

.withOptions {
  $0.loggerOutput = CleanroomLockLogger()
}

Was this helpful?

/

In the code above, the loggerOutput has been set to use CleanroomLogger. This can typically be achieved by implementing the loggerOutput protocol. You can of course use your favorite logger library. Below is an example of usage handling logger output with CleanroomLogger.

class CleanroomLockLogger: LoggerOutput {
  func message(_ message: String, level: LoggerLevel, filename: String, line: Int) {
    let channel: LogChannel?
    switch level {
    case .debug:
        channel = Log.debug
    case .error:
        channel = Log.error
    case .info:
        channel = Log.info
    case .verbose:
        channel = Log.verbose
    case .warn:
        channel = Log.warning
    default:
        channel = nil
    }
    channel?.message(message, filePath: filename, fileLine: line)
  }
}

Was this helpful?

/