Skip to content

hlandao/SwiftLoggerInspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftLoggerInspector

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

  1. import SwiftLoggerInspector in any file you want to use it.
  2. 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)
    
  3. Call loggerInspectorDestination.presentInspector()
  4. 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()
            }
        }
    }

About

On screen logs inspector for XCGLogger

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages