Skip to content

Commit a17f509

Browse files
authored
Add logging to project initialization (#8322)
This logs any issues from project setup in `FlutterInitializer` to our dedicated log file. The log variable from `protected val log` is internal, and I'm not sure why (despite asking Gemini multiple questions about it). That's why I'm accessing the log from a function instead.
1 parent 79663b0 commit a17f509

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

flutter-idea/src/io/flutter/FlutterInitializer.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.intellij.openapi.application.ApplicationManager;
1919
import com.intellij.openapi.application.ModalityState;
2020
import com.intellij.openapi.application.ReadAction;
21-
import com.intellij.openapi.diagnostic.Logger;
2221
import com.intellij.openapi.editor.colors.EditorColorsListener;
2322
import com.intellij.openapi.editor.colors.EditorColorsManager;
2423
import com.intellij.openapi.extensions.PluginId;
@@ -41,7 +40,6 @@
4140
import io.flutter.devtools.RemainingDevToolsViewFactory;
4241
import io.flutter.editor.FlutterSaveActionsManager;
4342
import io.flutter.logging.FlutterConsoleLogManager;
44-
import io.flutter.logging.PluginLogger;
4543
import io.flutter.module.FlutterModuleBuilder;
4644
import io.flutter.pub.PubRoot;
4745
import io.flutter.pub.PubRoots;
@@ -58,7 +56,6 @@
5856
import io.flutter.utils.OpenApiUtils;
5957
import io.flutter.view.InspectorViewFactory;
6058
import org.jetbrains.annotations.NotNull;
61-
import org.jetbrains.annotations.Nullable;
6259

6360
import java.util.ArrayList;
6461
import java.util.List;
@@ -75,7 +72,6 @@
7572
* may run when a project is being imported.
7673
*/
7774
public class FlutterInitializer extends FlutterProjectActivity {
78-
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterInitializer.class);
7975
private boolean toolWindowsInitialized = false;
8076

8177
private boolean busSubscribed = false;
@@ -84,7 +80,7 @@ public class FlutterInitializer extends FlutterProjectActivity {
8480

8581
@Override
8682
public void executeProjectStartup(@NotNull Project project) {
87-
LOG.info("Executing Flutter plugin startup for project: " + project.getName());
83+
log().info("Executing Flutter plugin startup for project: " + project.getName());
8884
// Disable the 'Migrate Project to Gradle' notification.
8985
FlutterUtils.disableGradleProjectMigrationNotification(project);
9086

@@ -109,7 +105,7 @@ public void executeProjectStartup(@NotNull Project project) {
109105
continue;
110106
}
111107

112-
LOG.info("Flutter module has been found for project: " + project.getName());
108+
log().info("Flutter module has been found for project: " + project.getName());
113109
// Ensure SDKs are configured; needed for clean module import.
114110
FlutterModuleUtils.enableDartSDK(module);
115111

@@ -130,7 +126,6 @@ public void executeProjectStartup(@NotNull Project project) {
130126
}
131127
}
132128

133-
134129
// Lambdas need final vars.
135130
boolean finalHasFlutterModule = hasFlutterModule;
136131
ReadAction.nonBlocking(() -> {
@@ -283,29 +278,29 @@ private void sendThemeChangedEvent(@NotNull Project project) {
283278
final DtdUtils dtdUtils = new DtdUtils();
284279
final DartToolingDaemonService dtdService = dtdUtils.readyDtdService(project).get();
285280
if (dtdService == null) {
286-
LOG.error("Unable to send theme changed event because DTD service is null");
281+
log().error("Unable to send theme changed event because DTD service is null");
287282
return;
288283
}
289284

290285
dtdService.sendRequest("postEvent", params, false, object -> {
291286
JsonObject result = object.getAsJsonObject("result");
292287
if (result == null) {
293-
LOG.error("Theme changed event returned null result");
288+
log().error("Theme changed event returned null result");
294289
return;
295290
}
296291
JsonPrimitive type = result.getAsJsonPrimitive("type");
297292
if (type == null) {
298-
LOG.error("Theme changed event result type is null");
293+
log().error("Theme changed event result type is null");
299294
return;
300295
}
301296
if (!"Success".equals(type.getAsString())) {
302-
LOG.error("Theme changed event result: " + type.getAsString());
297+
log().error("Theme changed event result: " + type.getAsString());
303298
}
304299
}
305300
);
306301
}
307302
catch (WebSocketException | InterruptedException | ExecutionException e) {
308-
LOG.error("Unable to send theme changed event", e);
303+
log().error("Unable to send theme changed event", e);
309304
}
310305
}, 1, TimeUnit.SECONDS);
311306
}

flutter-idea/src/io/flutter/FlutterProjectActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ package io.flutter
99
import com.intellij.openapi.diagnostic.Logger
1010
import com.intellij.openapi.project.Project
1111
import com.intellij.openapi.startup.ProjectActivity
12+
import io.flutter.logging.PluginLogger
1213

1314
abstract class FlutterProjectActivity : ProjectActivity {
1415

15-
protected val log = Logger.getInstance(this::class.java)
16+
protected val log = PluginLogger.createLogger(this::class.java)
1617
abstract fun executeProjectStartup(project: Project)
1718

1819
override suspend fun execute(project: Project) {
@@ -22,4 +23,8 @@ abstract class FlutterProjectActivity : ProjectActivity {
2223
log.error(it)
2324
}
2425
}
26+
27+
protected fun log(): Logger {
28+
return log;
29+
}
2530
}

flutter-idea/src/io/flutter/logging/PluginLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class PluginLogger {
3030
fileHandler.setFormatter(new SimpleFormatter());
3131
}
3232

33-
public static Logger createLogger(@NotNull Class<?> logClass) {
33+
public static @NotNull Logger createLogger(@NotNull Class<?> logClass) {
3434
java.util.logging.Logger.getLogger(logClass.getName()).addHandler(fileHandler);
3535
return Logger.getInstance(logClass.getName());
3636
}

0 commit comments

Comments
 (0)