How can I get the console logs from the iOS Simulator?

前端 未结 13 1589
感情败类
感情败类 2020-11-27 09:24

I want to see what happens in the iOS Simulator if I\'m not testing the app in Xcode.

For example, if I open a link in the Safari simulator, see what happens in the

13条回答
  •  青春惊慌失措
    2020-11-27 09:59

    No NSLog or print content will write to system.log, which can be open by Select Simulator -> Debug -> Open System log on Xcode 11.

    I figure out a way, write logs into a file and open the xx.log with Terminal.app.Then the logs will present in Terminal.app lively.

    I use CocoaLumberjack achieve this.

    STEP 1:

    Add DDFileLogger DDOSLogger and print logs path. config() should be called when App lunch.

    static func config() {
        #if DEBUG
        DDLog.add(DDOSLogger.sharedInstance) // Uses os_log
        let fileLogger: DDFileLogger = DDFileLogger() // File Logger
        fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hours
        fileLogger.logFileManager.maximumNumberOfLogFiles = 7
        DDLog.add(fileLogger)
        DDLogInfo("DEBUG LOG PATH: " + (fileLogger.currentLogFileInfo?.filePath ?? ""))
        #endif
    }
    

    STEP 2:

    Replace print or NSLog with DDLogXXX.

    STEP 3:

    $ tail -f {path of log}
    

    Here, message will present in Terminal.app lively.

    One thing more. If there is no any message log out, make sure Environment Variables -> OS_ACTIVITY_MODE ISNOT disable.

提交回复
热议问题