Skip to content

Commit 668e56b

Browse files
authored
[logging] Convert LaunchState, SdkFields to separate plugin logger (#8452)
1 parent de3ef6b commit 668e56b

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/io/flutter/FlutterUtils.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,36 @@ public static boolean isAndroidStudio() {
111111
}
112112
}
113113

114+
public static void info(@NotNull Logger logger, @NotNull Exception e) {
115+
info(logger, e, false);
116+
}
117+
118+
public static void info(@NotNull Logger logger, @NotNull Exception e, boolean sanitizePaths) {
119+
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
120+
logger.info(e);
121+
} else {
122+
logger.info(e.toString());
123+
}
124+
}
125+
126+
public static void warn(@NotNull Logger logger, @NotNull Exception e) {
127+
warn(logger, e, false);
128+
}
129+
130+
public static void warn(@NotNull Logger logger, @NotNull Exception e, boolean sanitizePaths) {
131+
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
132+
logger.warn(e);
133+
} else {
134+
logger.warn(e.toString());
135+
}
136+
}
137+
114138
/**
115139
* Write a warning message to the IntelliJ log.
116140
* <p>
117141
* This is separate from LOG.warn() to allow us to decorate the behavior.
142+
*
143+
* This method is deprecated (as we are not decorating this behavior anywhere).
118144
*/
119145
public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
120146
logger.warn(t);
@@ -124,6 +150,8 @@ public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
124150
* Write a warning message to the IntelliJ log.
125151
* <p>
126152
* This is separate from LOG.warn() to allow us to decorate the behavior.
153+
*
154+
* This method is deprecated (as we are not decorating this behavior anywhere).
127155
*/
128156
public static void warn(@NotNull Logger logger, @NotNull String message) {
129157
logger.warn(message);
@@ -133,6 +161,8 @@ public static void warn(@NotNull Logger logger, @NotNull String message) {
133161
* Write a warning message to the IntelliJ log.
134162
* <p>
135163
* This is separate from LOG.warn() to allow us to decorate the behavior.
164+
*
165+
* This method is deprecated (as we are not decorating this behavior anywhere).
136166
*/
137167
public static void warn(@NotNull Logger logger, @NotNull String message, @NotNull Throwable t) {
138168
logger.warn(message, t);

src/io/flutter/run/LaunchState.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import io.flutter.FlutterConstants;
4646
import io.flutter.FlutterUtils;
4747
import io.flutter.dart.DartPlugin;
48+
import io.flutter.logging.PluginLogger;
4849
import io.flutter.run.bazel.BazelRunConfig;
4950
import io.flutter.run.common.RunMode;
5051
import io.flutter.run.daemon.DaemonConsoleView;
@@ -180,7 +181,7 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws
180181
}
181182
}
182183
catch (IllegalAccessException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException e) {
183-
LOG.info(e);
184+
FlutterUtils.info(LOG, e, true);
184185
}
185186

186187
return descriptor;
@@ -401,7 +402,7 @@ protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNul
401402
app.shutdownAsync().get();
402403
}
403404
catch (InterruptedException | java.util.concurrent.ExecutionException e) {
404-
FlutterUtils.warn(LOG, e);
405+
FlutterUtils.warn(LOG, e, true);
405406
}
406407
return launchState.launch(env);
407408
}
@@ -458,5 +459,5 @@ public static ProcessHandler getRunningAppProcess(@NotNull RunConfig config) {
458459

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

461-
private static final @NotNull Logger LOG = Logger.getInstance(LaunchState.class);
462+
private static final @NotNull Logger LOG = PluginLogger.createLogger(LaunchState.class);
462463
}

src/io/flutter/run/SdkFields.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import com.jetbrains.lang.dart.sdk.DartConfigurable;
2020
import com.jetbrains.lang.dart.sdk.DartSdk;
2121
import io.flutter.FlutterBundle;
22+
import io.flutter.FlutterUtils;
2223
import io.flutter.dart.DartPlugin;
24+
import io.flutter.logging.PluginLogger;
2325
import io.flutter.pub.PubRoot;
2426
import io.flutter.pub.PubRootCache;
2527
import io.flutter.run.common.RunMode;
@@ -40,7 +42,7 @@
4042
* Fields used when launching an app using the Flutter SDK (non-bazel).
4143
*/
4244
public class SdkFields {
43-
private static final @NotNull Logger LOG = Logger.getInstance(SdkFields.class);
45+
private static final @NotNull Logger LOG = PluginLogger.createLogger(SdkFields.class);
4446
private @Nullable String filePath;
4547
private @Nullable String buildFlavor;
4648
private @Nullable String additionalArgs;
@@ -231,7 +233,7 @@ public GeneralCommandLine createFlutterSdkRunCommand(
231233
args = ArrayUtil.append(args, "--devtools-server-address=http://" + instance.host() + ":" + instance.port());
232234
}
233235
catch (Exception e) {
234-
LOG.info(e);
236+
FlutterUtils.warn(LOG, e, true);
235237
}
236238
command = flutterSdk.flutterRun(root, main.getFile(), device, runMode, flutterLaunchMode, project, args);
237239
final GeneralCommandLine commandLine = command.createGeneralCommandLine(project);

0 commit comments

Comments
 (0)