Skip to content

Add a separate file for plugin logs #8253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/runConfigurations/flutter_intellij__runIde_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions flutter-idea/src/io/flutter/FlutterInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.flutter.devtools.RemainingDevToolsViewFactory;
import io.flutter.editor.FlutterSaveActionsManager;
import io.flutter.logging.FlutterConsoleLogManager;
import io.flutter.logging.PluginLogger;
import io.flutter.module.FlutterModuleBuilder;
import io.flutter.pub.PubRoot;
import io.flutter.pub.PubRoots;
Expand Down Expand Up @@ -74,8 +75,7 @@
* may run when a project is being imported.
*/
public class FlutterInitializer extends FlutterProjectActivity {
private static final @NotNull Logger LOG = Logger.getInstance(FlutterInitializer.class);

private static final @NotNull Logger LOG = PluginLogger.createLogger(FlutterInitializer.class);
private boolean toolWindowsInitialized = false;

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

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

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

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

Expand Down
37 changes: 37 additions & 0 deletions flutter-idea/src/io/flutter/logging/PluginLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2025 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.logging;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.SimpleFormatter;

public class PluginLogger {
private static final String LOG_FILE_NAME = "flutter.log";
private static final FileHandler fileHandler;
static {
final String logPath = PathManager.getLogPath();
try {
fileHandler = new FileHandler(logPath + File.separatorChar + LOG_FILE_NAME, 1024 * 1024, 1);
}
catch (IOException e) {
throw new RuntimeException(e);
}
System.setProperty("java.util.logging.SimpleFormatter.format",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd that you can't set format properties programmatically. (I see you can use a logging properties file but that's no better.)

Anyway: odd!

"%1$tF %1$tT %3$s [%4$-7s] %5$s %6$s %n");
fileHandler.setFormatter(new SimpleFormatter());
}

public static Logger createLogger(@NotNull Class<?> logClass) {
java.util.logging.Logger.getLogger(logClass.getName()).addHandler(fileHandler);
return Logger.getInstance(logClass.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.flutter.bazel.Workspace;
import io.flutter.bazel.WorkspaceCache;
import io.flutter.dart.DtdUtils;
import io.flutter.logging.PluginLogger;
import io.flutter.sdk.FlutterSdk;
import io.flutter.sdk.FlutterSdkUtil;
import io.flutter.utils.JsonUtils;
Expand All @@ -57,7 +58,7 @@
import java.util.concurrent.atomic.AtomicReference;

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

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