Skip to content

Commit 4ff8d77

Browse files
committed
Add a separate file for plugin logs
1 parent cdca115 commit 4ff8d77

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-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: 6 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,12 +84,15 @@ public class FlutterInitializer extends FlutterProjectActivity {
8484

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

91+
LOG.info("Starting watching for devices");
9092
// Start watching for devices.
9193
DeviceService.getInstance(project);
9294

95+
LOG.info("Starting a DevTools server");
9396
// Start a DevTools server
9497
DevToolsService.getInstance(project);
9598

@@ -108,6 +111,7 @@ public void executeProjectStartup(@NotNull Project project) {
108111
continue;
109112
}
110113

114+
LOG.info("This is a Flutter module");
111115
// Ensure SDKs are configured; needed for clean module import.
112116
FlutterModuleUtils.enableDartSDK(module);
113117

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
10+
import java.io.File;
11+
import java.io.FileWriter;
12+
import java.io.IOException;
13+
import java.util.logging.Handler;
14+
import java.util.logging.LogRecord;
15+
16+
public class PluginLogHandler extends Handler {
17+
private static final String LOG_FILE_NAME = "flutter.log";
18+
public PluginLogHandler() {
19+
}
20+
21+
@Override
22+
public void publish(LogRecord record) {
23+
// Write to a file
24+
final String logPath = PathManager.getLogPath();
25+
System.out.println("Log path: " + logPath);
26+
File logFile = new File(logPath + File.separatorChar + LOG_FILE_NAME);
27+
28+
try {
29+
if (!logFile.exists()) {
30+
logFile.createNewFile(); // Create the file if it doesn't exist
31+
System.out.println("Log file created: " + logFile.getAbsolutePath());
32+
}
33+
FileWriter writer = new FileWriter(logFile, true); // Append to the file
34+
35+
String message = record.getInstant().toString() + " " + record.getLevel() + ": " + record.getMessage() + System.lineSeparator();
36+
writer.write(message); // Write the log message
37+
writer.close(); // Close the writer
38+
} catch (IOException e) {
39+
System.err.println("Error creating or writing to the log file: " + e.getMessage());
40+
}
41+
}
42+
43+
@Override
44+
public void flush() {
45+
System.out.println("LOG FLUSH: ");
46+
}
47+
48+
@Override
49+
public void close() throws SecurityException {
50+
System.out.println("in close of logging");
51+
}
52+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.diagnostic.Logger;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
public class PluginLogger {
12+
public static Logger createLogger(@NotNull Class logClass) {
13+
java.util.logging.Logger.getLogger(logClass.getName()).addHandler(new PluginLogHandler());
14+
return Logger.getInstance(logClass.getName());
15+
}
16+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import io.flutter.bazel.Workspace;
3939
import io.flutter.bazel.WorkspaceCache;
4040
import io.flutter.dart.DtdUtils;
41+
import io.flutter.logging.PluginLogHandler;
42+
import io.flutter.logging.PluginLogger;
4143
import io.flutter.sdk.FlutterSdk;
4244
import io.flutter.sdk.FlutterSdkUtil;
4345
import io.flutter.utils.JsonUtils;
@@ -57,7 +59,7 @@
5759
import java.util.concurrent.atomic.AtomicReference;
5860

5961
class DevToolsServerTask extends Task.Backgroundable {
60-
private @NotNull static final Logger LOG = Logger.getInstance(DevToolsServerTask.class);
62+
private @NotNull static final Logger LOG = PluginLogger.createLogger(DevToolsServerTask.class);
6163
public @NotNull static final String LOCAL_DEVTOOLS_DIR = "flutter.local.devtools.dir";
6264
public @NotNull static final String LOCAL_DEVTOOLS_ARGS = "flutter.local.devtools.args";
6365
private @NotNull final Project project;
@@ -79,6 +81,7 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
7981
try {
8082
progressIndicator.setFraction(30);
8183
progressIndicator.setText2("Init");
84+
LOG.info("Here we are in DevTools run");
8285

8386
// If DevTools is not supported, start the daemon instead.
8487
final boolean dartDevToolsSupported = dartSdkSupportsDartDevTools();

0 commit comments

Comments
 (0)