OktaLogger is a proxy-based logging SDK for allowing an app to log to many destinations at once, allowing for easy error and metric reporting without extraneous noise.
This SDK is available through CocoaPods. To install it, add the following line to your Podfile:
pod 'OktaLogger', :git => 'https://github.com/okta/okta-logger-swift.git'
There are few available subspecs:
Core- Contains only basic functionality and Console logger destination;
FileLogger- Core + File logger destination;
FirebaseCrashlytics- Core + Firebase Crashlytics logger destination;
Complete- Includes all available functionality. This subspec will be used by default.
This SDK is available through Swift Package Manager. To install it, import it from the following url:
There are few available products available to import:
OktaLoggerCore- Contains only basic functionality and Console logger destination;
OktaFileLogger- Core + File logger destination;
OktaFirebaseCrashlytics- Core + Firebase Crashlytics logger destination;
OktaInstabugLogger- Core + Instabug logger destination;
OktaLogger- Includes all available functionality;
To start using OktaLogger you need to initialize
OktaLogger object. Initializer takes
destinations array as parameter, so you can specify which destinations your logger will use. Please note that each destination should have unique identifier. New destination with existing ID won't be added. You can find more information about logging destinations in the related section.
// Initialization let consoleDestination = OktaLoggerConsoleLogger( identifier: "com.okta.consoleLogger", level: .all, defaultProperties: nil ) let logger = OktaLogger(destinations: [consoleDestination])
OktaLogger object is ready to track events:
// Logging logger.info(eventName: "Start enrollment", message: nil) logger.error(eventName: "TOTP Failure", message: "Could not retrieve key for RSA Key: ab43csd")
To add or remove destinations use
removeDestination(withIdentifier:) methods of
// Edit destinations let firebaseDestination = OktaFirebaseDestination( crashlytics: Crashlytics.crashlytics(), identifier: "com.okta.firebaseLogger", level: .error ) logger.addDestination(firebaseDestination) logger.removeDestination(withIdentifier: consoleDestination.identifier)
setLogLevel(level:, identifiers:) method to change log level of any destination(s):
// Changing log levels logger.setLogLevel(level: [.warn, .error], identifiers: [console.identifier, firebase.identifier])
Destination is an entity which perform log operation according to its implementation. Destinations should conforms to
OktaLoggerDestinationProtocol. There are 3 default destinations which provided by OktaLogger SDK:
All of the default logging destinations are thread-safe and could be used from any thread.
Destination instance has an ID string to store and identify it in the
OktaLogger. You can use any format for identifier. We recommend to use reverse-domain format with app Bundle ID and destination name in it.
Each destination has its own log level that specifies which messages should be processed by it. Please, refer to related section to find out more about log levels.
Each destination also has
defaultProperties parameter. This is key-value structure that could be used for storing some general information like user ID, app version, etc. Default destinations including string representation of this structure in the every log message. You can modify default properties with
Related class - OktaLoggerConsoleLogger.
This destination is using
os_log function to print log messages to the console. It does not contain any 3rd party dependencies and mainly used during the XCode debug sessions.
Related class - OktaLoggerFileLogger.
The purpose of this destination is storing logs on the disk.
There are several features available:
File logging destination is using CocoaLumberjack for logging implementation.
Related class - OktaLoggerFirebaseCrashlyticsLogger.
This destination is using FirebaseCrashlytics SDK to log messages, so they can be accessed from Firebase console.
There are few important features and restrictions in this destination:
Crashlyticsobject to the destination initializer.
errorlevels are sent as non-fatal events. These logs are also added to non-fatal and fatal error reports.
uiEventare added as custom log messages. These logs can be accessible only in scope of fatal or non-fatal errors.
<destination id>.<event name>. For example, "Push register failed" error event has
This destination is using Firebase Crashlytics SDK for logging implementation.
Related class -
This destination uses the AppCenter SDK to send events, so they can be accessed from the App Center console. The only functionality supported by this destination is sending events to the App Center dashboard. There are a few important features and restrictions in this destination:
This destination is using App Center SDK for logging implementation
Related class -
This destination uses the Instabug SDK to send events, so they can be accessed from the Instabug console in bug report or improvement suggestion. There are a few important features and restrictions in this destination:
|OktaLogger log level||Instabug log method|
This destination is using Instabug iOS SDK for logging implementation.
If you want to create your custom destination it is recommended to inherit it from
OktaLoggerDestinationBase class, as this class implements some basic functionality. Hovewer, the only requirement for destinations is to conform to
If you choose to inherit from
OktaLoggerDestinationBase, than you need to implement
log() method in order to make it work. You can use
stringValue() method to receive default log message string representation. Please, refer to OktaLoggerConsoleLogger as an example of logger destination implementation.
OktaLogger provides 7 log levels:
Every destination has its own level, so you can change it separately for each of them. Logging destinations will only log events which match against their level(s).
For example, the following console logger will ignore
debug logs, but will process logs with level
let consoleLogger = OktaLoggerConsoleLogger(identifier: "console.logger", level: [.info, .warn, .error])` let logger = OktaLogger(destinations: [consoleLogger])
Logging level can be changed at runtime using
setLogLevel(level:, identifiers:) method of
OktaLogger or by changing
level property in
logger.setLogLevel(level: .all, destinations: [consoleLogger.identifier]) // or consoleLogger.level = .all
|Last commit: 1 week ago|
Minor internal fixes and improvements. No changes to any public interfaces.