Please note that this will also log your logs to a local file - USE ONLY IN DEBUG
Show XCGLogger logs on a running device.
- Add the following to your podfile
pod 'XCGLogger', '~> 3.3'
- run
pod install
import SwiftLoggerInspector
in any file you want to use it.- 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)
- Call
loggerInspectorDestination.presentInspector()
- Use XCGLogger as you'd always do.
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()
}
}
}