LogsManager 12.4.0

LogsManager 12.4.0

Maintained by Anton Plebanovich.



 
Depends on:
APExtensions/Occupiable>= 10.1.6
CocoaLumberjack/Swift>= 3.7.2
RoutableLogger>= 11.0.0
 

  • By
  • Anton Plebanovich

LogsManager

Carthage compatible Swift Package Manager compatible Version License Platform CI Status

Logs manager on top of CocoaLumberjack. Allows to easily configure log components depending on your app infrastucture. Have several convenience loggers: ConsoleLogger, AlertLogger, NotificationLogger.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Swift Package Manager

  • In Xcode select File > Add Packages...
  • Copy and paste the following into the search: https://github.com/APUtils/LogsManager
  • ‼️Make sure Up to Next Major Version is selected and put 12.3.0 into the lower bound. There is a bug in Xcode, it does not select versions higher than 9.0.0 by default‼️
  • Tap Add Package
  • Select LogsManager to add everything and tap Add Package

CocoaPods

LogsManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

For the main app target:

pod 'LogsManager', '~> 12.3'

For the app extension target:

pod 'LogsManager/Core', '~> 12.3'

Carthage DEPRECATED

Please check official guide

Cartfile:

github "APUtils/LogsManager" "9.1.19"

Install command: carthage bootstrap

Add LogsManager framework to the main app and app extensions if any. Add LogsManagerExtensionUnsafe framework for the main app only (excluding app extensions if any).

Carthage with XCFrameworks DEPRECATED

Please check official guide

Cartfile:

github "APUtils/LogsManager" "9.1.20"

Install command: carthage bootstrap --use-xcframeworks

Add LogsManager framework to the main app and app extensions if any. Add LogsManagerExtensionUnsafe framework for the main app only (excluding app extensions if any).

Usage

You have to add logs component first if you want your logs to be separated by components:

let vcComponent = LogComponent(name: "ViewController", logName: "VC") { filePath, _ in
    let fileName = String.getFileName(filePath: filePath)
    return fileName == "ViewController"
}
LoggersManager.shared.registerLogComponent(vcComponent)

let didAppearComponent = LogComponent(name: "Did Appear", logName: "viewDidAppear") { _, function in
    return function.hasPrefix("viewDidAppear")
}
LoggersManager.shared.registerLogComponent(didAppearComponent)

Then you need to add loggers and specify their components and log levels:

// Log all ViewController debug messages
let logger = ConsoleLogger(logComponents: [vcComponent], logLevel: .debug, newLinesSeparation: false)
LoggersManager.shared.addTextLogger(logger)

// Present alert for any error log
let allAlertLogger = AlertLogger(logComponents: nil, logLevel: .error)
LoggersManager.shared.addTextLogger(allAlertLogger)

You can use convenience global function to leave logs:

logInfo("Staring network request to: \(request.url)")
logDebug("Received data")
logVerbose("Data payload: \(data)")
logError("Got error response", error: error, data: ["request": request])

See example and test projects for more details.

Contributions

Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.

Author

Anton Plebanovich, [email protected]

License

LogsManager is available under the MIT license. See the LICENSE file for more info.