Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Fix getting ios simulator device logs #815

Merged
merged 2 commits into from
Oct 5, 2016
Merged

Conversation

rosen-vladimirov
Copy link
Collaborator

@rosen-vladimirov rosen-vladimirov commented Oct 3, 2016

iOS Simulator device logs are printed directly to process.stdout from the ios-sim-portable. However this makes it really difficult to filter the logs and provide them to different callers (for example AppBuilder CLI, NativeScript CLI, Proton).
In order to fix this, use the ios-sim-portable just to start the process of getting device logs. Filter them in the CLI itself.
Also change the logic in ios-log-filter to use process pid in case it's passed. For iOS Simulator we have filtered logs based on the PID of the application. With these changes, simulator logs are passed to ios-log-filter, so that's why we need process' PID there.
When application is restarted (during livesync for example), we set the PID again and the filter will use the new PID.

Merge AFTER NativeScript/ios-sim-portable#79

@justcodebuilduser
Copy link

❤️

@@ -174,7 +201,7 @@ declare module Mobile {
* @param {string} logLevel Selected logging level.
* @return {string} The filtered result based on the input or null when the input data shouldn't be shown.
*/
filterData(data: string, logLevel: string): string;
filterData(data: string, logLevel: string, pid: string): string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add JSDocs for pid

@@ -142,6 +142,32 @@ declare module Mobile {
interface IDeviceLogProvider {
logData(line: string, platform: string, deviceIdentifier: string): void;
setLogLevel(level: string, deviceIdentifier?: string): void;
setApplictionPidForDevice(deviceIdentifier: string, pid: string): void;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add JSDocs

@Mitko-Kerezov
Copy link
Contributor

LGTM 👍

@justcodebuilduser
Copy link

❤️

1 similar comment
@justcodebuilduser
Copy link

❤️

@justcodebuilduser
Copy link

❤️

@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/sim-logs branch 2 times, most recently from 57280ed to 71fd9f9 Compare October 3, 2016 11:18
@justcodebuilduser
Copy link

❤️

@justcodebuilduser
Copy link

💔

@rosen-vladimirov
Copy link
Collaborator Author

run ci

@justcodebuilduser
Copy link

❤️

@justcodebuilduser
Copy link

❤️

1 similar comment
@justcodebuilduser
Copy link

❤️

@justcodebuilduser
Copy link

❤️

iOS Simulator device logs are printed directly to process.stdout from the ios-sim-portable. However this makes it really difficult to filter the logs and provide them to different callers (for example AppBuilder CLI, NativeScript CLI, Proton).
In order to fix this, use the ios-sim-portable just to start the process of getting device logs. Filter them in the CLI itself.
Also change the logic in ios-log-filter to use process pid in case it's passed. For iOS Simulator we have filtered logs based on the PID of the application. With these changes, simulator logs are passed to ios-log-filter, so that's why we need process' PID there.
When application is restarted (during livesync for example), we set the PID again and the filter will use the new PID.

Add unit tests to verify passing PID to iOSLogFilter works correctly.
@justcodebuilduser
Copy link

❤️

if(deviceIdentifier) {
this.devicesLogLevel[deviceIdentifier] = logLevel.toUpperCase();
if (deviceIdentifier) {
this.devicesLogOptions[deviceIdentifier] = this.devicesLogOptions[deviceIdentifier] || <Mobile.IDeviceLogOptions> { };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this check and the set of the device log option on the line below in a method for example setDeviceLogOption:

protected setDeviceLogOption(deviceId: string, optionName: string, value: string): void {
    this.devicesLogOptions[deviceId] = this.devicesLogOptions[deviceId] || <Mobile.IDeviceLogOptions> { };
    this.devicesLogOptions[deviceId][optionName]= value;
}

_.each(this.devicesLogLevel, (deviceLogLevel: string, deviceId: string) => {
this.devicesLogLevel[deviceId] = this.$logFilter.loggingLevel;

_.each(this.devicesLogOptions, (deviceLogLevel: string, deviceId: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use _.keys here instead of _.each because you don't use the deviceLogLevel: string.

@rosen-vladimirov
Copy link
Collaborator Author

@TsvetanMilanov nice catch, comments are handled in the code ;)

@justcodebuilduser
Copy link

❤️

1 similar comment
@justcodebuilduser
Copy link

❤️

@justcodebuilduser
Copy link

❤️

logLevel = logLevel || this.$logFilter.loggingLevel;

if (deviceIdentifier) {
logLevel = (this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].logLevel) || this.$logFilter.loggingLevel;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code seems really strange. setLogLevelForDevice method does not use the passed logLevel.
Consider either removing the logLevel parameter or using it here:

logLevel = (this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].logLevel) || logLevel;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed ;)

In many cases we need the propertyName and pass it to another function. However in case we use string and rename the property in the future, we almost always forget to update the string.
Introduce helper function that accepts function as argument. The argument function must return the property which name we need.
Add unit tests for the helper method.

Use the new method to simplify setting of deviceLogOptions.
@justcodebuilduser
Copy link

❤️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants