Skip to content

[logging] Convert LaunchState, SdkFields to separate plugin logger #8452

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 6 commits into from
Aug 12, 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
30 changes: 30 additions & 0 deletions src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,36 @@ public static boolean isAndroidStudio() {
}
}

public static void info(@NotNull Logger logger, @NotNull Exception e) {
info(logger, e, false);
}

public static void info(@NotNull Logger logger, @NotNull Exception e, boolean sanitizePaths) {
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
logger.info(e);
} else {
logger.info(e.toString());
}
}

public static void warn(@NotNull Logger logger, @NotNull Exception e) {
warn(logger, e, false);
}

public static void warn(@NotNull Logger logger, @NotNull Exception e, boolean sanitizePaths) {
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
logger.warn(e);
} else {
logger.warn(e.toString());
}
}

/**
* Write a warning message to the IntelliJ log.
* <p>
* This is separate from LOG.warn() to allow us to decorate the behavior.
*
* This method is deprecated (as we are not decorating this behavior anywhere).
*/
public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
logger.warn(t);
Expand All @@ -124,6 +150,8 @@ public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
* Write a warning message to the IntelliJ log.
* <p>
* This is separate from LOG.warn() to allow us to decorate the behavior.
*
* This method is deprecated (as we are not decorating this behavior anywhere).
*/
public static void warn(@NotNull Logger logger, @NotNull String message) {
logger.warn(message);
Expand All @@ -133,6 +161,8 @@ public static void warn(@NotNull Logger logger, @NotNull String message) {
* Write a warning message to the IntelliJ log.
* <p>
* This is separate from LOG.warn() to allow us to decorate the behavior.
*
* This method is deprecated (as we are not decorating this behavior anywhere).
*/
public static void warn(@NotNull Logger logger, @NotNull String message, @NotNull Throwable t) {
logger.warn(message, t);
Expand Down
7 changes: 4 additions & 3 deletions src/io/flutter/run/LaunchState.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import io.flutter.FlutterConstants;
import io.flutter.FlutterUtils;
import io.flutter.dart.DartPlugin;
import io.flutter.logging.PluginLogger;
import io.flutter.run.bazel.BazelRunConfig;
import io.flutter.run.common.RunMode;
import io.flutter.run.daemon.DaemonConsoleView;
Expand Down Expand Up @@ -180,7 +181,7 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
}
}
catch (IllegalAccessException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException e) {
LOG.info(e);
FlutterUtils.info(LOG, e, true);
}

return descriptor;
Expand Down Expand Up @@ -401,7 +402,7 @@ protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNul
app.shutdownAsync().get();
}
catch (InterruptedException | java.util.concurrent.ExecutionException e) {
FlutterUtils.warn(LOG, e);
FlutterUtils.warn(LOG, e, true);
}
return launchState.launch(env);
}
Expand Down Expand Up @@ -458,5 +459,5 @@ public static ProcessHandler getRunningAppProcess(@NotNull RunConfig config) {

private static final Key<RunConfig> FLUTTER_RUN_CONFIG_KEY = new Key<>("FLUTTER_RUN_CONFIG_KEY");

private static final @NotNull Logger LOG = Logger.getInstance(LaunchState.class);
private static final @NotNull Logger LOG = PluginLogger.createLogger(LaunchState.class);
}
6 changes: 4 additions & 2 deletions src/io/flutter/run/SdkFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.jetbrains.lang.dart.sdk.DartConfigurable;
import com.jetbrains.lang.dart.sdk.DartSdk;
import io.flutter.FlutterBundle;
import io.flutter.FlutterUtils;
import io.flutter.dart.DartPlugin;
import io.flutter.logging.PluginLogger;
import io.flutter.pub.PubRoot;
import io.flutter.pub.PubRootCache;
import io.flutter.run.common.RunMode;
Expand All @@ -40,7 +42,7 @@
* Fields used when launching an app using the Flutter SDK (non-bazel).
*/
public class SdkFields {
private static final @NotNull Logger LOG = Logger.getInstance(SdkFields.class);
private static final @NotNull Logger LOG = PluginLogger.createLogger(SdkFields.class);
private @Nullable String filePath;
private @Nullable String buildFlavor;
private @Nullable String additionalArgs;
Expand Down Expand Up @@ -231,7 +233,7 @@ public GeneralCommandLine createFlutterSdkRunCommand(
args = ArrayUtil.append(args, "--devtools-server-address=http://" + instance.host() + ":" + instance.port());
}
catch (Exception e) {
LOG.info(e);
FlutterUtils.warn(LOG, e, true);
}
command = flutterSdk.flutterRun(root, main.getFile(), device, runMode, flutterLaunchMode, project, args);
final GeneralCommandLine commandLine = command.createGeneralCommandLine(project);
Expand Down