Latest 0.1.2
Homepage https://github.com/Dtroupe18/SwiftDebugLog
License MIT
Platforms ios 11.0
Authors

CI Status
Version
License
Platform

Simple Swift Debug Logger inspired by this medium post

Purpose:

  1. Global wrapping of the print function. All print statements will be removed at compile time unless your code is compiled in Debug. Debug printing in production can be done using: Log.logProduction(error)

  2. Allows you to easily log errors that include the file name, line, and function name without additional typing.

Sample Output:

2019-02-17 15:29:25.627-0500 🐛🐛🐛🐛 [ViewController.swift] line: 25 logInProduction() -> This log always prints!

2019-02-17 15:29:25.633-0500 😡 [ViewController.swift] line: 33 trySomething() -> The item couldn’t be opened because the file name “” is invalid.

2019-02-17 15:29:25.633-0500 🕵 [ViewController.swift] line: 43 makeApiCall() -> ["userId": 1, "id": 1, "title": "delectus aut autem"]

2019-02-17 15:29:25.634-0500 ⚠️ [ViewController.swift] line: 48 doSomethingWith(optional:) -> Optional is nil!

2019-02-17 15:29:25.634-0500 🚨🚨 [ViewController.swift] line: 55 doSomethingReallyImportant(shouldCrash:) -> Crashing for some reason

Code to create the above logging:

    func logInProduction() {
        // This should only be used when debugging in production!
        Log.logProduction("This log always prints!")
    }

    func trySomething() {
        do {
        // Something that might throw an error
            let _ = try String(contentsOfFile: "")
        } catch let error {
            Log.logError(error.localizedDescription)
        }
    }

    func makeApiCall() {
        let json: [String: Any] = [
            "userId": 1,
            "id": 1,
            "title": "delectus aut autem"
        ]

        Log.logDebug(json)
    }

    func doSomethingWith(optional: String?) {
        guard let string = optional else {
            Log.logWarning("Optional is nil!")
            return
        }
    }

    func doSomethingReallyImportant(shouldCrash: Bool) {
        if shouldCrash {
            Log.logSevere("Crashing for some reason")
            fatalError()
        }
    }

Logging Levels

  1. Error = 😡
  2. Debug = 🕵
  3. Warning = ⚠️
  4. Severe = 🚨🚨
  5. Production = 🐛🐛🐛🐛

Example

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

Installation

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

pod 'SwiftDebugLog'

or copy and paste Log.swift into your project! Using this method prevents you from having to import SwiftDebugLog in your files and it also globally wraps print into debug only.

License

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

Latest podspec

{
    "name": "SwiftDebugLog",
    "version": "0.1.2",
    "summary": "Lightweight Swift Debug Logger",
    "swift_version": "4.0",
    "description": "Swift library for logging errors in debug. Log statements include the filename, line, and function call.",
    "homepage": "https://github.com/Dtroupe18/SwiftDebugLog",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dtroupe18": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Dtroupe18/SwiftDebugLog.git",
        "tag": "0.1.2"
    },
    "platforms": {
        "ios": "11.0"
    },
    "source_files": "SwiftDebugLog/Classes/**/*"
}

Pin It on Pinterest

Share This