Skip to content

Commit 5631957

Browse files
authored
Use separate log for FlutterCommand (#8339)
I added an option (default off) to record full file paths in logs. Originally I was thinking that we shouldn't record any file paths, but it seems reasonable to have them sometimes for debugging setup issues since these are recorded on a user's machine rather than to somewhere centralized that we receive by default.
1 parent 270a0bd commit 5631957

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

flutter-idea/src/io/flutter/FlutterBundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ settings.report.analytics.tooltip=Report anonymized usage information to Google
157157
settings.enable.verbose.logging.tooltip=Enables verbose logging (this can be useful for diagnostic purposes).
158158
# suppress inspection "UnusedProperty" (used in a `FlutterSettingsConfigurable.form`)
159159
settings.enable.logs.preserve.during.hot.reload.and.restart=Preserve console logs during Hot Reload and Hot Restart
160+
settings.enable.file.path.logging=Allow logging of full file paths
161+
settings.enable.file.path.logging.tooltip=Logs full file paths that could show private user information
160162

161163
action.new.project.title=New Flutter Project...
162164
welcome.new.project.compact=New Flutter Project

flutter-idea/src/io/flutter/sdk/FlutterCommand.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@
1919
import io.flutter.android.IntelliJAndroidSdk;
2020
import io.flutter.console.FlutterConsoles;
2121
import io.flutter.dart.DartPlugin;
22+
import io.flutter.logging.PluginLogger;
23+
import io.flutter.settings.FlutterSettings;
2224
import io.flutter.utils.MostlySilentColoredProcessHandler;
2325
import org.jetbrains.annotations.NotNull;
2426
import org.jetbrains.annotations.Nullable;
2527

2628
import java.nio.charset.StandardCharsets;
29+
import java.nio.file.Path;
2730
import java.util.*;
2831
import java.util.function.Consumer;
2932

3033
/**
3134
* A Flutter command to run, with its arguments.
3235
*/
3336
public class FlutterCommand {
34-
private static final @NotNull Logger LOG = Logger.getInstance(FlutterCommand.class);
37+
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterCommand.class);
3538

3639
private static final Set<Type> pubRelatedCommands = new HashSet<>(
3740
Arrays.asList(Type.PUB_GET, Type.PUB_UPGRADE, Type.PUB_OUTDATED, Type.UPGRADE));
@@ -166,7 +169,7 @@ public String toString() {
166169
public ColoredProcessHandler startProcess(boolean sendAnalytics) {
167170
try {
168171
final GeneralCommandLine commandLine = createGeneralCommandLine(null);
169-
LOG.info(commandLine.toString());
172+
LOG.info(safeCommandLog(commandLine));
170173
return new ColoredProcessHandler(commandLine);
171174
}
172175
catch (ExecutionException e) {
@@ -194,7 +197,7 @@ public FlutterCommandStartResult startProcess(@Nullable Project project) {
194197
final ColoredProcessHandler handler;
195198
try {
196199
final GeneralCommandLine commandLine = createGeneralCommandLine(project);
197-
LOG.info(commandLine.toString());
200+
LOG.info(safeCommandLog(commandLine));
198201
handler = new MostlySilentColoredProcessHandler(commandLine);
199202
handler.addProcessListener(new ProcessAdapter() {
200203
@Override
@@ -290,4 +293,14 @@ enum Type {
290293
this.subCommand = ImmutableList.copyOf(subCommand);
291294
}
292295
}
296+
297+
private @NotNull String safeCommandLog(@NotNull GeneralCommandLine commandLine) {
298+
if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
299+
final String fullString = commandLine.toString();
300+
return fullString != null ? fullString : "";
301+
}
302+
303+
final Path path = Path.of(commandLine.getExePath());
304+
return path.getFileName() + commandLine.getParametersList().toString();
305+
}
293306
}

flutter-idea/src/io/flutter/sdk/FlutterSettingsConfigurable.form

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</component>
6060
</children>
6161
</grid>
62-
<grid id="e885c" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
62+
<grid id="e885c" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
6363
<margin top="0" left="0" bottom="0" right="0"/>
6464
<constraints>
6565
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -85,6 +85,15 @@
8585
<toolTipText resource-bundle="io/flutter/FlutterBundle" key="settings.allow.tests.tooltip"/>
8686
</properties>
8787
</component>
88+
<component id="1a5b8" class="javax.swing.JCheckBox" binding="myEnableFilePathLogging">
89+
<constraints>
90+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
91+
</constraints>
92+
<properties>
93+
<text resource-bundle="io/flutter/FlutterBundle" key="settings.enable.file.path.logging"/>
94+
<toolTipText resource-bundle="io/flutter/FlutterBundle" key="settings.enable.file.path.logging.tooltip"/>
95+
</properties>
96+
</component>
8897
</children>
8998
</grid>
9099
<grid id="919ec" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

flutter-idea/src/io/flutter/sdk/FlutterSettingsConfigurable.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class FlutterSettingsConfigurable implements SearchableConfigurable {
8686
private JCheckBox myAllowTestsInSourcesRoot;
8787
private ActionLink settingsLink;
8888
private JCheckBox myEnableLogsPreserveAfterHotReloadOrRestart;
89+
private @NotNull JCheckBox myEnableFilePathLogging;
8990

9091
private final @NotNull Project myProject;
9192
private final WorkspaceCache workspaceCache;
@@ -245,6 +246,10 @@ public boolean isModified() {
245246
return true;
246247
}
247248

249+
if (settings.isFilePathLoggingEnabled() != myEnableFilePathLogging.isSelected()) {
250+
return true;
251+
}
252+
248253
return settings.isEnableJcefBrowser() != myEnableJcefBrowserCheckBox.isSelected();
249254
}
250255

@@ -299,6 +304,7 @@ public void apply() throws ConfigurationException {
299304
settings.setAllowTestsInSourcesRoot(myAllowTestsInSourcesRoot.isSelected());
300305
settings.setFontPackages(myFontPackagesTextArea.getText());
301306
settings.setEnableJcefBrowser(myEnableJcefBrowserCheckBox.isSelected());
307+
settings.setFilePathLoggingEnabled(myEnableFilePathLogging.isSelected());
302308

303309
reset(); // because we rely on remembering initial state
304310
checkFontPackages(settings.getFontPackages(), oldFontPackages);
@@ -366,6 +372,7 @@ public void reset() {
366372

367373
myEnableJcefBrowserCheckBox.setSelected(settings.isEnableJcefBrowser());
368374
myFontPackagesTextArea.setText(settings.getFontPackages());
375+
myEnableFilePathLogging.setSelected(settings.isFilePathLoggingEnabled());
369376
}
370377

371378
private void onVersionChanged() {

flutter-idea/src/io/flutter/settings/FlutterSettings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class FlutterSettings {
3535
private static final String showBazelIosRunNotificationKey = "io.flutter.hideBazelIosRunNotification";
3636
private static final String sdkVersionOutdatedWarningAcknowledgedKey = "io.flutter.sdkVersionOutdatedWarningAcknowledged";
3737
private static final String androidStudioBotAcknowledgedKey = "io.flutter.androidStudioBotAcknowledgedKey";
38+
private static final String enableFilePathLoggingKey = "io.flutter.enableFilePathLogging";
3839

3940
private static @Nullable FlutterSettings testInstance;
4041

@@ -261,4 +262,12 @@ public boolean isAndroidStudioBotAcknowledged() {
261262
public void setAndroidStudioBotAcknowledgedKey(boolean value) {
262263
getPropertiesComponent().setValue(androidStudioBotAcknowledgedKey, value);
263264
}
265+
266+
public boolean isFilePathLoggingEnabled() {
267+
return getPropertiesComponent().getBoolean(enableFilePathLoggingKey, false);
268+
}
269+
270+
public void setFilePathLoggingEnabled(boolean value) {
271+
getPropertiesComponent().setValue(enableFilePathLoggingKey, value);
272+
}
264273
}

0 commit comments

Comments
 (0)