Skip to content

Can enable debug logging of the gRPC calls. #1065

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

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions arduino-ide-extension/src/browser/arduino-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ export const ArduinoConfigSchema: PreferenceSchema = {
),
default: true,
},
'arduino.cli.daemon.debug': {
type: 'boolean',
description: nls.localize(
'arduino/preferences/cli.daemonDebug',
"Enable debug logging of the gRPC calls to the Arduino CLI. A restart of the IDE is needed for this setting to take effect. It's false by default."
),
default: false,
},
},
};

Expand All @@ -207,6 +215,7 @@ export interface ArduinoConfiguration {
'arduino.auth.audience': string;
'arduino.auth.registerUri': string;
'arduino.survey.notification': boolean;
'arduino.cli.daemon.debug': boolean;
}

export const ArduinoPreferences = Symbol('ArduinoPreferences');
Expand Down
43 changes: 41 additions & 2 deletions arduino-ide-extension/src/node/arduino-daemon-impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from 'path';
import { promises as fs } from 'fs';
import { inject, injectable, named } from '@theia/core/shared/inversify';
import { spawn, ChildProcess } from 'child_process';
import { FileUri } from '@theia/core/lib/node/file-uri';
Expand Down Expand Up @@ -142,9 +143,12 @@ export class ArduinoDaemonImpl
}

protected async getSpawnArgs(): Promise<string[]> {
const configDirUri = await this.envVariablesServer.getConfigDirUri();
const [configDirUri, debug] = await Promise.all([
this.envVariablesServer.getConfigDirUri(),
this.debugDaemon(),
]);
const cliConfigPath = join(FileUri.fsPath(configDirUri), CLI_CONFIG);
return [
const args = [
'daemon',
'--format',
'jsonmini',
Expand All @@ -156,6 +160,41 @@ export class ArduinoDaemonImpl
'--log-format',
'json',
];
if (debug) {
args.push('--debug');
}
Comment on lines +163 to +165
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be useful to let the user set the debug file too, like this:

Suggested change
if (debug) {
args.push('--debug');
}
if (debug) {
args.push('--debug');
if (debugFilePath) {
args.push('--debug-file');
args.push(debugFilePath);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

but in that case, we should take care about deleting the file after every start-up, otherwise the file size will grow indefinitely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

I edited the commit message and the PR; my changes won't close #1056. I will let you wrap it up when you have figured out how to do the file-based logging.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kittaakos ok I asked @cmaglie to make a change in the arduino-cli in order to recreate the log file every time the IDE is restarted. In the meantime, I'm going to add the flag because it already works anyway

return args;
}

private async debugDaemon(): Promise<boolean> {
// Poor man's preferences on the backend. (https://github.com/arduino/arduino-ide/issues/1056#issuecomment-1153975064)
const configDirUri = await this.envVariablesServer.getConfigDirUri();
const configDirPath = FileUri.fsPath(configDirUri);
try {
const raw = await fs.readFile(join(configDirPath, 'settings.json'), {
encoding: 'utf8',
});
const json = this.tryParse(raw);
if (json) {
const value = json['arduino.cli.daemon.debug'];
return typeof value === 'boolean' && !!value;
}
return false;
} catch (error) {
if ('code' in error && error.code === 'ENOENT') {
return false;
}
throw error;
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private tryParse(raw: string): any | undefined {
try {
return JSON.parse(raw);
} catch {
return undefined;
}
}

protected async spawnDaemonProcess(): Promise<{
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"board.certificates": "List of certificates that can be uploaded to boards",
"browse": "Browse",
"choose": "Choose",
"cli.daemonDebug": "Enable debug logging of the gRPC calls to the Arduino CLI. A restart of the IDE is needed for this setting to take effect. It's false by default.",
"cloud.enabled": "True if the sketch sync functions are enabled. Defaults to true.",
"cloud.pull.warn": "True if users should be warned before pulling a cloud sketch. Defaults to true.",
"cloud.push.warn": "True if users should be warned before pushing a cloud sketch. Defaults to true.",
Expand Down