Skip to content

Commit f87aa68

Browse files
authored
Convert run files to use PluginLogger (#8526)
Part of #8369
1 parent e2f137e commit f87aa68

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

src/io/flutter/FlutterUtils.java

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

114-
public static void info(@NotNull Logger logger, @NotNull String message, @NotNull Exception e, boolean sanitizePaths) {
114+
public static void info(@NotNull Logger logger, @NotNull String message, @NotNull Throwable t, boolean sanitizePaths) {
115115
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
116-
logger.info(message, e);
116+
logger.info(message, t);
117117
} else {
118118
logger.info(message);
119119
}
120120
}
121121

122-
public static void warn(@NotNull Logger logger, @NotNull String message, @NotNull Exception e, boolean sanitizePaths) {
122+
public static void warn(@NotNull Logger logger, @NotNull String message, @NotNull Throwable t, boolean sanitizePaths) {
123123
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
124-
logger.warn(message, e);
124+
logger.warn(message, t);
125125
} else {
126126
logger.warn(message);
127127
}
128128
}
129129

130+
public static void error(@NotNull Logger logger, @NotNull String message, @NotNull Throwable t, boolean sanitizePaths) {
131+
if (sanitizePaths && FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
132+
logger.error(message, t);
133+
} else {
134+
logger.error(message);
135+
}
136+
}
137+
130138
/**
131139
* Write a warning message to the IntelliJ log.
132140
* <p>

src/io/flutter/run/FlutterDebugProcess.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.flutter.actions.ReloadFlutterApp;
2424
import io.flutter.actions.RestartAllFlutterApps;
2525
import io.flutter.actions.RestartFlutterApp;
26+
import io.flutter.logging.PluginLogger;
2627
import io.flutter.run.common.RunMode;
2728
import io.flutter.run.daemon.FlutterApp;
2829
import io.flutter.view.FlutterViewMessages;
@@ -42,7 +43,7 @@
4243
* when not debugging in order to support hot reload.)
4344
*/
4445
public class FlutterDebugProcess extends DartVmServiceDebugProcess {
45-
private static final @NotNull Logger LOG = Logger.getInstance(FlutterDebugProcess.class);
46+
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterDebugProcess.class);
4647

4748
private final @NotNull FlutterApp app;
4849

@@ -141,7 +142,7 @@ private static void suppressDebugViews(@Nullable RunnerLayoutUi ui) {
141142
}
142143
}
143144
catch (ProcessCanceledException e) {
144-
FlutterUtils.warn(LOG, "Failed to suppress debug views", e, true);
145+
FlutterUtils.warn(LOG, "ProcessCanceledException in suppressDebugViews", e, true);
145146
throw e;
146147
}
147148
}

src/io/flutter/run/FlutterPositionMapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.jetbrains.lang.dart.util.DartUrlResolver;
2323
import io.flutter.FlutterUtils;
2424
import io.flutter.dart.DartPlugin;
25+
import io.flutter.logging.PluginLogger;
2526
import io.flutter.utils.OpenApiUtils;
2627
import io.flutter.vmService.DartVmServiceDebugProcess;
2728
import org.dartlang.vm.service.element.LibraryRef;
@@ -40,7 +41,7 @@
4041
* Used when setting breakpoints, stepping through code, and so on while debugging.
4142
*/
4243
public class FlutterPositionMapper implements DartVmServiceDebugProcess.PositionMapper {
43-
private static final @NotNull Logger LOG = Logger.getInstance(FlutterPositionMapper.class);
44+
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterPositionMapper.class);
4445

4546
/**
4647
* This Project can't be non-null as we set it to null {@link #shutdown()} so the Project isn't held onto.
@@ -257,7 +258,7 @@ private XSourcePosition getSourcePosition(@NotNull final String isolateId, @NotN
257258
private XSourcePosition getSourcePosition(@NotNull final String isolateId, @NotNull final String scriptId,
258259
@NotNull final String scriptUri, int tokenPos, CompletableFuture<String> fileFuture) {
259260
if (scriptProvider == null) {
260-
FlutterUtils.warn(LOG, "attempted to get source position before connected to observatory");
261+
LOG.warn("attempted to get source position before connected to observatory");
261262
return null;
262263
}
263264

@@ -379,13 +380,13 @@ static Analyzer create(@NotNull Project project, @NotNull VirtualFile sourceLoca
379380
}
380381

381382
if (!dartAnalysisServerService.serverReadyForRequest()) {
382-
FlutterUtils.warn(LOG, "Dart analysis server is not running. Some breakpoints may not work.");
383+
LOG.warn("Dart analysis server is not running. Some breakpoints may not work.");
383384
return null;
384385
}
385386

386387
final String contextId = dartAnalysisServerService.execution_createContext(sourceLocation.getPath());
387388
if (contextId == null) {
388-
FlutterUtils.warn(LOG, "Failed to get execution context from analysis server. Some breakpoints may not work.");
389+
LOG.warn("Failed to get execution context from analysis server. Some breakpoints may not work.");
389390
return null;
390391
}
391392

src/io/flutter/run/FlutterReloadManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import io.flutter.bazel.Workspace;
5656
import io.flutter.bazel.WorkspaceCache;
5757
import io.flutter.dart.FlutterDartAnalysisServer;
58+
import io.flutter.logging.PluginLogger;
5859
import io.flutter.run.common.RunMode;
5960
import io.flutter.run.daemon.FlutterApp;
6061
import io.flutter.settings.FlutterSettings;
@@ -74,7 +75,7 @@
7475
* Handle the mechanics of performing a hot reload on file save.
7576
*/
7677
public class FlutterReloadManager {
77-
private static final @NotNull Logger LOG = Logger.getInstance(FlutterReloadManager.class);
78+
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterReloadManager.class);
7879

7980
private static final Map<String, NotificationGroup> toolWindowNotificationGroups = new HashMap<>();
8081

@@ -142,7 +143,7 @@ public void beforeActionPerformed(@NotNull AnAction action, @NotNull AnActionEve
142143
}
143144
catch (Throwable t) {
144145
// A catch-all, so any exceptions don't bubble through to the users.
145-
LOG.warn("Exception from FlutterReloadManager", t);
146+
FlutterUtils.warn(LOG, "Exception from FlutterReloadManager", t, true);
146147
}
147148
}
148149

@@ -161,7 +162,7 @@ public void afterActionPerformed(@NotNull AnAction action, @NotNull AnActionEven
161162
handleSaveAllNotification(eventEditor);
162163
}
163164
catch (Throwable t) {
164-
FlutterUtils.warn(LOG, "Exception from hot reload on save", t);
165+
FlutterUtils.warn(LOG, "Exception from hot reload on save", t, true);
165166
}
166167
finally {
167168
// Context: "Released EditorImpl held by lambda in FlutterReloadManager" (https://github.com/flutter/flutter-intellij/issues/7507)
@@ -325,7 +326,7 @@ private void syncFiles() {
325326
}
326327
}
327328
catch (ExecutionException | InterruptedException e) {
328-
LOG.error("Unable to sync files: " + e);
329+
FlutterUtils.error(LOG, "Unable to sync files", e, true);
329330
}
330331
}
331332

src/io/flutter/run/OpenDevToolsAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313
import com.intellij.openapi.project.Project;
1414
import com.intellij.openapi.util.Computable;
1515
import icons.FlutterIcons;
16+
import io.flutter.FlutterUtils;
1617
import io.flutter.ObservatoryConnector;
1718
import io.flutter.bazel.WorkspaceCache;
1819
import io.flutter.devtools.DevToolsIdeFeature;
1920
import io.flutter.devtools.DevToolsUrl;
21+
import io.flutter.logging.PluginLogger;
2022
import io.flutter.run.daemon.DevToolsService;
2123
import io.flutter.run.daemon.FlutterApp;
2224
import io.flutter.sdk.FlutterSdk;
25+
import io.flutter.settings.FlutterSettings;
2326
import io.flutter.utils.AsyncUtils;
2427
import org.jetbrains.annotations.NotNull;
2528
import org.jetbrains.annotations.Nullable;
2629

2730
import java.util.Objects;
2831

2932
public class OpenDevToolsAction extends DumbAwareAction {
30-
private static final @NotNull Logger LOG = Logger.getInstance(OpenDevToolsAction.class);
33+
private static final @NotNull Logger LOG = PluginLogger.createLogger(OpenDevToolsAction.class);
3134
private static final String title = "Open Flutter DevTools in Browser";
3235
private final @Nullable ObservatoryConnector myConnector;
3336
private final Computable<Boolean> myIsApplicable;
@@ -76,7 +79,7 @@ public void actionPerformed(@NotNull final AnActionEvent event) {
7679
}
7780

7881
if (ex != null) {
79-
LOG.error(ex);
82+
FlutterUtils.error(LOG, "Exception in getDevToolsInstance", ex, true);
8083
return;
8184
}
8285

src/io/flutter/run/SdkRunConfig.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
import io.flutter.FlutterUtils;
4141
import io.flutter.console.FlutterConsoleFilter;
4242
import io.flutter.dart.FlutterDartAnalysisServer;
43+
import io.flutter.logging.PluginLogger;
4344
import io.flutter.run.common.RunMode;
4445
import io.flutter.run.daemon.FlutterApp;
4546
import io.flutter.sdk.FlutterSdkManager;
47+
import io.flutter.settings.FlutterSettings;
4648
import org.jdom.Element;
4749
import org.jetbrains.annotations.NotNull;
4850
import org.jetbrains.annotations.Nullable;
@@ -59,7 +61,7 @@
5961
public class SdkRunConfig extends LocatableConfigurationBase<LaunchState>
6062
implements LaunchState.RunConfig, RefactoringListenerProvider, RunConfigurationWithSuppressedDefaultRunAction {
6163

62-
private static final @NotNull Logger LOG = Logger.getInstance(SdkRunConfig.class);
64+
private static final @NotNull Logger LOG = PluginLogger.createLogger(SdkRunConfig.class);
6365
private boolean firstRun = true;
6466

6567
private @NotNull SdkFields fields = new SdkFields();
@@ -117,7 +119,7 @@ public static class RecursiveDeleter extends SimpleFileVisitor<Path> {
117119

118120
@Override
119121
public @NotNull FileVisitResult visitFileFailed(@NotNull Path file, @NotNull IOException exc) {
120-
FlutterUtils.warn(LOG, "Unable to visit file", exc, true);
122+
FlutterUtils.warn(LOG, "Unable to visit file in RecursiveDeleter", exc, true);
121123
return CONTINUE;
122124
}
123125
}
@@ -165,7 +167,8 @@ public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnviro
165167
existingJson = Files.readString(cachedParametersPath);
166168
}
167169
catch (IOException e) {
168-
FlutterUtils.warn(LOG, "Unable to get existing json from " + cachedParametersPath);
170+
LOG.warn("Unable to get existing json from " +
171+
(FlutterSettings.getInstance().isFilePathLoggingEnabled() ? cachedParametersPath : cachedParametersPath.getFileName()));
169172
}
170173
}
171174
if (!StringUtil.equals(json, existingJson)) {

0 commit comments

Comments
 (0)