Skip to content

[logging] Use separate log for FlutterCommand #8339

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
Jul 17, 2025
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
2 changes: 2 additions & 0 deletions flutter-idea/src/io/flutter/FlutterBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ settings.report.analytics.tooltip=Report anonymized usage information to Google
settings.enable.verbose.logging.tooltip=Enables verbose logging (this can be useful for diagnostic purposes).
# suppress inspection "UnusedProperty" (used in a `FlutterSettingsConfigurable.form`)
settings.enable.logs.preserve.during.hot.reload.and.restart=Preserve console logs during Hot Reload and Hot Restart
settings.enable.file.path.logging=Allow logging of full file paths
settings.enable.file.path.logging.tooltip=Logs full file paths that could show private user information

action.new.project.title=New Flutter Project...
welcome.new.project.compact=New Flutter Project
Expand Down
19 changes: 16 additions & 3 deletions flutter-idea/src/io/flutter/sdk/FlutterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
import io.flutter.android.IntelliJAndroidSdk;
import io.flutter.console.FlutterConsoles;
import io.flutter.dart.DartPlugin;
import io.flutter.logging.PluginLogger;
import io.flutter.settings.FlutterSettings;
import io.flutter.utils.MostlySilentColoredProcessHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Consumer;

/**
* A Flutter command to run, with its arguments.
*/
public class FlutterCommand {
private static final @NotNull Logger LOG = Logger.getInstance(FlutterCommand.class);
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterCommand.class);

private static final Set<Type> pubRelatedCommands = new HashSet<>(
Arrays.asList(Type.PUB_GET, Type.PUB_UPGRADE, Type.PUB_OUTDATED, Type.UPGRADE));
Expand Down Expand Up @@ -166,7 +169,7 @@ public String toString() {
public ColoredProcessHandler startProcess(boolean sendAnalytics) {
try {
final GeneralCommandLine commandLine = createGeneralCommandLine(null);
LOG.info(commandLine.toString());
LOG.info(safeCommandLog(commandLine));
return new ColoredProcessHandler(commandLine);
}
catch (ExecutionException e) {
Expand Down Expand Up @@ -194,7 +197,7 @@ public FlutterCommandStartResult startProcess(@Nullable Project project) {
final ColoredProcessHandler handler;
try {
final GeneralCommandLine commandLine = createGeneralCommandLine(project);
LOG.info(commandLine.toString());
LOG.info(safeCommandLog(commandLine));
handler = new MostlySilentColoredProcessHandler(commandLine);
handler.addProcessListener(new ProcessAdapter() {
@Override
Expand Down Expand Up @@ -290,4 +293,14 @@ enum Type {
this.subCommand = ImmutableList.copyOf(subCommand);
}
}

private @NotNull String safeCommandLog(@NotNull GeneralCommandLine commandLine) {
if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
final String fullString = commandLine.toString();
return fullString != null ? fullString : "";
}

final Path path = Path.of(commandLine.getExePath());
return path.getFileName() + commandLine.getParametersList().toString();
}
}
11 changes: 10 additions & 1 deletion flutter-idea/src/io/flutter/sdk/FlutterSettingsConfigurable.form
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</component>
</children>
</grid>
<grid id="e885c" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e885c" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
Expand All @@ -85,6 +85,15 @@
<toolTipText resource-bundle="io/flutter/FlutterBundle" key="settings.allow.tests.tooltip"/>
</properties>
</component>
<component id="1a5b8" class="javax.swing.JCheckBox" binding="myEnableFilePathLogging">
<constraints>
<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"/>
</constraints>
<properties>
<text resource-bundle="io/flutter/FlutterBundle" key="settings.enable.file.path.logging"/>
<toolTipText resource-bundle="io/flutter/FlutterBundle" key="settings.enable.file.path.logging.tooltip"/>
</properties>
</component>
</children>
</grid>
<grid id="919ec" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class FlutterSettingsConfigurable implements SearchableConfigurable {
private JCheckBox myAllowTestsInSourcesRoot;
private ActionLink settingsLink;
private JCheckBox myEnableLogsPreserveAfterHotReloadOrRestart;
private @NotNull JCheckBox myEnableFilePathLogging;

private final @NotNull Project myProject;
private final WorkspaceCache workspaceCache;
Expand Down Expand Up @@ -245,6 +246,10 @@ public boolean isModified() {
return true;
}

if (settings.isFilePathLoggingEnabled() != myEnableFilePathLogging.isSelected()) {
return true;
}

return settings.isEnableJcefBrowser() != myEnableJcefBrowserCheckBox.isSelected();
}

Expand Down Expand Up @@ -299,6 +304,7 @@ public void apply() throws ConfigurationException {
settings.setAllowTestsInSourcesRoot(myAllowTestsInSourcesRoot.isSelected());
settings.setFontPackages(myFontPackagesTextArea.getText());
settings.setEnableJcefBrowser(myEnableJcefBrowserCheckBox.isSelected());
settings.setFilePathLoggingEnabled(myEnableFilePathLogging.isSelected());

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

myEnableJcefBrowserCheckBox.setSelected(settings.isEnableJcefBrowser());
myFontPackagesTextArea.setText(settings.getFontPackages());
myEnableFilePathLogging.setSelected(settings.isFilePathLoggingEnabled());
}

private void onVersionChanged() {
Expand Down
9 changes: 9 additions & 0 deletions flutter-idea/src/io/flutter/settings/FlutterSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class FlutterSettings {
private static final String showBazelIosRunNotificationKey = "io.flutter.hideBazelIosRunNotification";
private static final String sdkVersionOutdatedWarningAcknowledgedKey = "io.flutter.sdkVersionOutdatedWarningAcknowledged";
private static final String androidStudioBotAcknowledgedKey = "io.flutter.androidStudioBotAcknowledgedKey";
private static final String enableFilePathLoggingKey = "io.flutter.enableFilePathLogging";

private static @Nullable FlutterSettings testInstance;

Expand Down Expand Up @@ -261,4 +262,12 @@ public boolean isAndroidStudioBotAcknowledged() {
public void setAndroidStudioBotAcknowledgedKey(boolean value) {
getPropertiesComponent().setValue(androidStudioBotAcknowledgedKey, value);
}

public boolean isFilePathLoggingEnabled() {
return getPropertiesComponent().getBoolean(enableFilePathLoggingKey, false);
}

public void setFilePathLoggingEnabled(boolean value) {
getPropertiesComponent().setValue(enableFilePathLoggingKey, value);
}
}