Dead simple logging library for iOS

Logr

Simple logging library for iOS written in Swift.

Features

  • [x] Inferred log message tags
  • [x] Swift Package Manager/Carthage/CocoaPods integration
  • [x] Highly extensible
  • [x] Logging to multiple targets/destination at the same time
  • [x] Console logging out of the box via ConsoleTarget
  • [x] File logging out of the box via FileTarget
  • [x] Pure Swift 5
  • [x] Optional file header for each file
  • [x] Automatic file archive based on size or time span

Integration

Swift Package Manager

Once Swift package set up, add the following to your Package.swift:

dependencies: [
  .package(url: "https://github.com/nakkht/logr.git", exact: "0.11.0")
]

Usage

In your AppDelegate.swift file add:

import Logr

At the beginning of func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool configure logr service with wanted targets:

LogrService.init(with: Config(ConsoleTarget(), FileTarget()))

For more serious configuration in production, it is recommended to ommit ConsoleTarget. For example:

#if DEBUG
static let targets: [Target] = [ConsoleTarget(), FileTarget()]
#else
static let targets: [Target] = [FileTarget()]
#endif

static let config = Config(targets: targets)

LogrService.init(with: config)

The set targets will be used across the whole application.

To log messages, simply create Logr instance in class initializer and start logging. For example:

import Logr

class ViewController: UIViewController {

    private let logr = Logr()

    func logDebug() {
        logr.debug("debug message to be logged")
    }
}

Demo

Demo project can be access by opening Demo.workspace in Demo sub-folder.

GitHub

https://github.com/nakkht/logr