Swiftpack.co - Package - bojan/Troop

Troop

A lightweight logging utility for iOS, macOS, watchOS and tvOS.

Build Status GitHub license Carthage compatible SPM codecov

Features

  • [x] Swift 5 support
  • [x] Modern syntax
  • [x] OSLog support
  • [x] Custom logging destinations

Requirements

Installation

Swift Packager Manager (SPM)

Create a Package.swift file, and add this snippet:

import PackageDescription

let package = Package(
    name: "HelloWorld",
    dependencies: [
        .Package(url: "https://github.com/bojan/Troop.git")
    ]
)

Carthage

Add this to your Cartfile:

github "bojan/Troop"

Manually

Add the repository as a submodule to your project.

git submodule add https://github.com/bojan/Troop.git Vendor/Troop

Open the newly created folder in Finder and drag Troop.xcodeproj to your project.

In your project's settings, select your target and under General > Embedded Binaries, add the framework depending on the target OS (iOS, macOS, watchOS or tvOS).

Usage

Import the module where needed:

import Troop

Configuration

let configuration: Troop.Configuration = {
    var configuration = Troop.Configuration(prefix: "some-prefix", level: .debug)
    #if DEBUG
        configuration.level = .verbose
    #endif

    return configuration
}()

let log = Troop(configuration: Logger.configuration, destination: UnifiedLogDestination(subsystem: configuration.prefix, category: "Your App"))

Logging statements

Use any of the following logging statements according to the level you need to be logged:

Verbose

log.verbose(message)

Info

log.info(message)

Error

log.error(message)

Debug

log.debug(message)

Warning

log.warning(message)

Example wrapper

In order to avoid using global variables and importing the framework in multiple files, use this wrapper:

struct Logger {

	private static let configuration: Troop.Configuration = {
		var configuration = Troop.Configuration(prefix: "some-prefix", level: .debug)
		#if DEBUG
			configuration.level = .verbose
		#endif

		return configuration
	}()
	private static let log = Troop(configuration: Logger.configuration, destination: UnifiedLogDestination(subsystem: configuration.prefix, category: "Your App"))

	static func verbose(_ message: String) {
		log.verbose(message)
	}

	static func info(_ message: String) {
		log.info(message)
	}

	static func error(_ message: String) {
		log.error(message)
	}

	static func debug(_ message: String) {
		log.debug(message)
	}

	static func warning(_ message: String) {
		log.warning(message)
	}

}

Contributions

All contributions and suggestions are welcome and very much appreciated.

Should you have a feature request or a problem that you may experience, feel free to open an issue.

If you are willing to contribute by adding a feature or squashing a bug or two, please submit a pull request.

Author

Bojan Dimovski

License

Troop is available under the WTFPL license. Check the LICENSE file for more info.

Github

link
Stars: 3
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.1.1 - Oct 8, 2019

  • SPM fixes.

1.0.0 - Oct 8, 2019

1.1.0 - Oct 8, 2019

  • Added support for Swift Package Manager.
  • Added support for the latest Xcode and Swift versions.
  • Updated documentation and license.
  • Added code coverage.

1.0.1 - Oct 8, 2019

Added wrappers for better readability when referencing the Troop objects.