Skip to content

Commit 42b9ec4

Browse files
authored
Add a separate file for plugin logs (#8253)
This adds a new class `PluginLogger` that prints log messages to a separate `flutter.log` file. Log messages will continue to print to `idea.log` also because `PluginLogger` has a parent logger that continues to log there. The built in `FileHandler` class manages writing to the file and removing old lines if the file gets too big.
1 parent 4407e9d commit 42b9ec4

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

.idea/runConfigurations/flutter_intellij__runIde_.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import io.flutter.devtools.RemainingDevToolsViewFactory;
4242
import io.flutter.editor.FlutterSaveActionsManager;
4343
import io.flutter.logging.FlutterConsoleLogManager;
44+
import io.flutter.logging.PluginLogger;
4445
import io.flutter.module.FlutterModuleBuilder;
4546
import io.flutter.pub.PubRoot;
4647
import io.flutter.pub.PubRoots;
@@ -74,8 +75,7 @@
7475
* may run when a project is being imported.
7576
*/
7677
public class FlutterInitializer extends FlutterProjectActivity {
77-
private static final @NotNull Logger LOG = Logger.getInstance(FlutterInitializer.class);
78-
78+
private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterInitializer.class);
7979
private boolean toolWindowsInitialized = false;
8080

8181
private boolean busSubscribed = false;
@@ -84,6 +84,7 @@ public class FlutterInitializer extends FlutterProjectActivity {
8484

8585
@Override
8686
public void executeProjectStartup(@NotNull Project project) {
87+
LOG.info("Executing Flutter plugin startup for project: " + project.getName());
8788
// Disable the 'Migrate Project to Gradle' notification.
8889
FlutterUtils.disableGradleProjectMigrationNotification(project);
8990

@@ -108,6 +109,7 @@ public void executeProjectStartup(@NotNull Project project) {
108109
continue;
109110
}
110111

112+
LOG.info("Flutter module has been found for project: " + project.getName());
111113
// Ensure SDKs are configured; needed for clean module import.
112114
FlutterModuleUtils.enableDartSDK(module);
113115

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
package io.flutter.logging;
7+
8+
import com.intellij.openapi.application.PathManager;
9+
import com.intellij.openapi.diagnostic.Logger;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
import java.io.File;
13+
import java.io.IOException;
14+
import java.util.logging.FileHandler;
15+
import java.util.logging.SimpleFormatter;
16+
17+
public class PluginLogger {
18+
private static final String LOG_FILE_NAME = "flutter.log";
19+
private static final FileHandler fileHandler;
20+
static {
21+
final String logPath = PathManager.getLogPath();
22+
try {
23+
fileHandler = new FileHandler(logPath + File.separatorChar + LOG_FILE_NAME, 1024 * 1024, 1);
24+
}
25+
catch (IOException e) {
26+
throw new RuntimeException(e);
27+
}
28+
System.setProperty("java.util.logging.SimpleFormatter.format",
29+
"%1$tF %1$tT %3$s [%4$-7s] %5$s %6$s %n");
30+
fileHandler.setFormatter(new SimpleFormatter());
31+
}
32+
33+
public static Logger createLogger(@NotNull Class<?> logClass) {
34+
java.util.logging.Logger.getLogger(logClass.getName()).addHandler(fileHandler);
35+
return Logger.getInstance(logClass.getName());
36+
}
37+
}

flutter-idea/src/io/flutter/run/daemon/DevToolsServerTask.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.flutter.bazel.Workspace;
3939
import io.flutter.bazel.WorkspaceCache;
4040
import io.flutter.dart.DtdUtils;
41+
import io.flutter.logging.PluginLogger;
4142
import io.flutter.sdk.FlutterSdk;
4243
import io.flutter.sdk.FlutterSdkUtil;
4344
import io.flutter.utils.JsonUtils;
@@ -57,7 +58,7 @@
5758
import java.util.concurrent.atomic.AtomicReference;
5859

5960
class DevToolsServerTask extends Task.Backgroundable {
60-
private @NotNull static final Logger LOG = Logger.getInstance(DevToolsServerTask.class);
61+
private @NotNull static final Logger LOG = PluginLogger.createLogger(DevToolsServerTask.class);
6162
public @NotNull static final String LOCAL_DEVTOOLS_DIR = "flutter.local.devtools.dir";
6263
public @NotNull static final String LOCAL_DEVTOOLS_ARGS = "flutter.local.devtools.args";
6364
private @NotNull final Project project;
@@ -79,6 +80,7 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
7980
try {
8081
progressIndicator.setFraction(30);
8182
progressIndicator.setText2("Init");
83+
LOG.info("Finding or starting DevTools");
8284

8385
// If we are in a Bazel workspace, start the server.
8486
// Note: This is only for internal usages.

0 commit comments

Comments
 (0)