Latest 0.0.4
Homepage https://github.com/hlandao/SwiftLoggerInspector
License MIT
Platforms ios 8.0, requires ARC
Dependencies SnapKit, XCGLogger
Frameworks Foundation
Authors

Swift 2.2
Platforms OS X | iOS | watchOS
License MIT

Please note that this will also log your logs to a local file – USE ONLY IN DEBUG

tl;dr

Show XCGLogger logs on a running device.

Install

  1. Add the following to your podfile pod 'XCGLogger', '~> 3.3'
  2. run pod install

    Integrate

  3. import SwiftLoggerInspector in any file you want to use it.
  4. Add LoggerInspectorDestination as a log destination to your XCGLogger.

    import XCGLogger
    import SwiftLoggerInspector
    ...
    var logger = XCGLogger.defaultInstance()
    var loggerInspectorDestination: LoggerInspectorDestination!
    
    loggerInspectorDestination = LoggerInspectorDestination(owner: logger, writeToFile: logFilePath())
    logger.addLogDestination(loggerInspectorDestination)
  5. Call loggerInspectorDestination.presentInspector()
  6. Use XCGLogger as you’d always do.

Example: Init in AppDelegate

Bonus: Present the inspector when shaking the device!

    var logger = XCGLogger.defaultInstance()
    var loggerInspectorDestination: LoggerInspectorDestination!

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        loggerInspectorDestination = LoggerInspectorDestination(owner: logger, writeToFile: logFilePath())
        logger.addLogDestination(loggerInspectorDestination)

        logger.debug("App delefate launched!")
        return true
    }

    // Log file path url
    func logFilePath() -> NSURL {
        let urls = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask)
        let url = urls[urls.endIndex - 1]
        return url.URLByAppendingPathComponent("myLogFile.log")
    }

    // Detect shaking gesture
    override func motionBegan(motion: UIEventSubtype,
                              withEvent event: UIEvent?) {
        if motion == .MotionShake{
            let logger = XCGLogger.defaultInstance()
            if let loggerInspectorDestination = logger.logDestinations.last as? LoggerInspectorDestination {
                loggerInspectorDestination.presentInspector()
            }
        }
    }

Latest podspec

{
    "name": "SwiftLoggerInspector",
    "version": "0.0.4",
    "summary": "On screen logs inspector for XCGLogger",
    "description": "A XCGLogger destination that lets you present to the logs on the screen of the running device",
    "platforms": {
        "ios": "8.0"
    },
    "homepage": "https://github.com/hlandao/SwiftLoggerInspector",
    "license": "MIT",
    "authors": {
        "Hadar Landao": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hlandao/SwiftLoggerInspector.git",
        "tag": "0.0.4"
    },
    "source_files": [
        "SwiftLoggerInspector/SwiftLoggerInspector/LoggerInspectorDestination.swift",
        "SwiftLoggerInspector/SwiftLoggerInspector/LoggerInspectorViewController.swift",
        "SwiftLoggerInspector/SwiftLoggerInspector/LogTableViewCell.swift"
    ],
    "dependencies": {
        "SnapKit": [
            "~> 0.19.1"
        ],
        "XCGLogger": [
            "~> 3.3"
        ]
    },
    "frameworks": "Foundation",
    "requires_arc": true
}

Pin It on Pinterest

Share This