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

前端 未结 13 1426
感情败类
感情败类 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:57

    If you are using Swift, remember that println will only print to the debug log (which appears in xCode's debug area). If you want to print to system.log, you have to use NSLog as in the old days.

    Then you can view the simulator log via its menu, Debug > Open System Log... (cmd + /)

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-27 10:03

    iOS Simulator > Menu Bar > Debug > Open System Log


    Old ways:

    iOS Simulator prints its logs directly to stdout, so you can see the logs mixed up with system logs.

    Open the Terminal and type: tail -f /var/log/system.log

    Then run the simulator.

    EDIT:

    This stopped working on Mavericks/Xcode 5. Now you can access the simulator logs in its own folder: ~/Library/Logs/iOS Simulator/<sim-version>/system.log

    You can either use the Console.app to see this, or just do a tail (iOS 7.0.3 64 bits for example):

    tail -f ~/Library/Logs/iOS\ Simulator/7.0.3-64/system.log

    EDIT 2:

    They are now located in ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log

    tail -f ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log

    0 讨论(0)
  • 2020-11-27 10:06

    XCode > 6.0 AND iOS > 8.0 The below script works if you have XCode version > 8.0

    I use the below small Script to tail the simulator logs onto the system console.

    #!/bin/sh
    sim_dir=`xcrun instruments -s | grep "iPhone 6 (8.2 Simulator)" | awk {'print $NF'} | tr -d '[]'`
    tail -f ~/Library/Logs/CoreSimulator/$sim_dir/system.log
    

    You can pass in the simulator type used in the Grep as an argument. As mentioned in the above posts, there are simctl and instruments command to view the type of simulators available for use depending on the Xcode version. To View the list of available devices/simulators.

    xcrun instruments -s
    

    OR

    xcrun simctl list
    

    Now you can pass in the Device code OR Simulator type as an argument to the script and replace the "iPhone 6 (8.2 Simulator)" inside grep to be $1

    0 讨论(0)
  • 2020-11-27 10:07

    I can open the log directly via the iOS simulator: Debug -> Open System Log... Not sure when this was introduced, so it might not be available for earlier versions.

    0 讨论(0)
  • 2020-11-27 10:08

    iOS 8 and iOS 9

    Under iOS 8 and iOS 9 this location is now:

    ~/Library/Logs/CoreSimulator/<DEVICE_CODE>
    

    So, the following will work:

    tail -f ~/Library/Logs/CoreSimulator/<DEVICE_CODE>/system.log
    

    The DEVICE_CODE value can be found via the following console command:

    instruments -s devices
    
    0 讨论(0)
提交回复
热议问题