Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No logging is done after an --exit #167

Open
shazron opened this issue Jul 8, 2015 · 5 comments
Open

No logging is done after an --exit #167

shazron opened this issue Jul 8, 2015 · 5 comments
Labels

Comments

@shazron
Copy link

shazron commented Jul 8, 2015

Unlike ios-sim 3.x, we can't log after the process exits.

@shazron
Copy link
Author

shazron commented Jul 14, 2015

Alternatives:

  1. symlink to actual log
  2. some out-of-process logging to file

@shazron shazron added the 4.x label Jul 16, 2015
@shazron shazron added this to the 4.2.0 milestone Jul 16, 2015
@haxpor
Copy link

haxpor commented Jul 19, 2015

Is this for logging during running of application as well? I cannot see logging message while running.

@shazron
Copy link
Author

shazron commented Jul 19, 2015

Yup logging for as long as the simulator is running, for the app. In 3.x even with --exit flag, you could log to file, but with 4.x, you can't.

@haxpor
Copy link

haxpor commented Jul 19, 2015

@shazron Alright! Thank you for info. I'm looking forward to this too.

@shazron shazron modified the milestones: 5.0.3, 5.1.0 Oct 12, 2015
@schlachtzeuger
Copy link

schlachtzeuger commented May 17, 2016

Hey all,

since I spent several days with this bug, I wanted to share my thoughts and my workaround/solution for this with you.

Even if you omit the --exit flag and send ios-sim to background using &, the logging isn't done right but old log entries can suddenly appear in the log output. The culprit for this isn't clear to me, as fs.watch in the Tail module gets a "rename" event even if the system.log of the emulator wasn't renamed. When that event was raised, all contents of the simulator's system.log gets copied into the log output again. So maybe it's an issue within the fs module, but I don't know.

In our scenario, we run unit tests with Jasmine in the emulator and need to wait for a specific line to determine if the tests were successful or not. My workaround is this little script:

#!/bin/bash

SIM_DEVICE="iPhone 5s"
SIM_IOS="9.1"

# modify device name for ios-sim
MOD_DEVICE=`echo $SIM_DEVICE | sed 's/ /-/'`

### check if there exists a simulator for the given DEVICE_NAME and IOS_VERSION
SIM_UDID=""

while read -r line
do
    if [[ "$line" =~ "${SIM_DEVICE} (${SIM_IOS})" ]]; then
    SIM_UDID=`echo $line | sed 's/^.*\[\(.*\)\]$/\1/'`
    fi
done < <(instruments -s devices)

if [ "$SIM_UDID" = "" ]; then
    echo "no matching device found"
    exit 1
fi

echo "Found simulator UDID: $SIM_UDID"

SIM_DIR=~/Library/Logs/CoreSimulator/${SIM_UDID}/

if [ ! -d "$SIM_DIR" ]; then
    echo "Simulator directory $SIM_DIR does not exist!"
    exit 1
fi


echo "building app"
phonegap  build ios

echo "clearing simulator log"
SIM_LOG=${SIM_DIR}/system.log
echo "" > ${SIM_LOG}

echo "starting simulator with app"
ios-sim launch platforms/ios/build/emulator/MyPhoneGapTest.app --devicetypeid "${MOD_DEVICE}, ${SIM_IOS}" --exit

echo "waiting for tests"

tail -f ${SIM_LOG} | while read LOGLINE
do
    [[ "${LOGLINE}" =~ ^.*#.*spec.*assertion.*failure.* ]] && pkill -P $$ tail
done

tail ${SIM_LOG} | grep "^.*#.*specs.*assertions.*failures.*"
cp ${SIM_LOG} ios.log

In the first part of the script, I get the emulator's UDID via the given device type and iOS version. Then I use Phonegap only to build the app but start it then in ios-sim manually. In the last part, I only wait for the expected line.

I hope that this script may be useful for others, too!

-- Max

@shazron shazron modified the milestones: 5.2.0, 5.3.0 Jun 10, 2017
@shazron shazron removed this from the 6.1.0 milestone Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants