Skip to content

[logging] Change DeviceDaemon to use separate log file #8454

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 1 commit into from
Aug 12, 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
11 changes: 0 additions & 11 deletions src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,6 @@ public static void warn(@NotNull Logger logger, @NotNull Exception e, boolean sa
}
}

/**
* Write a warning message to the IntelliJ log.
* <p>
* This is separate from LOG.warn() to allow us to decorate the behavior.
*
* This method is deprecated (as we are not decorating this behavior anywhere).
*/
public static void warn(@NotNull Logger logger, @NotNull Throwable t) {
logger.warn(t);
}

/**
* Write a warning message to the IntelliJ log.
* <p>
Expand Down
17 changes: 12 additions & 5 deletions src/io/flutter/run/daemon/DeviceDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
import io.flutter.android.IntelliJAndroidSdk;
import io.flutter.bazel.Workspace;
import io.flutter.bazel.WorkspaceCache;
import io.flutter.logging.PluginLogger;
import io.flutter.run.FlutterDevice;
import io.flutter.sdk.FlutterSdk;
import io.flutter.sdk.FlutterSdkUtil;
import io.flutter.settings.FlutterSettings;
import io.flutter.utils.FlutterModuleUtils;
import io.flutter.utils.MostlySilentColoredProcessHandler;
import io.flutter.utils.OpenApiUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -114,7 +117,7 @@ boolean needRestart(@NotNull Command next) {
*/
void shutdown() {
if (!process.isProcessTerminated()) {
LOG.info("shutting down Flutter device daemon #" + id + ": " + command);
LOG.info("shutting down Flutter device daemon #" + id + ": " + command.toString(FlutterSettings.getInstance().isFilePathLoggingEnabled()));
}
listener.running.set(false);
process.destroyProcess();
Expand Down Expand Up @@ -207,7 +210,7 @@ DeviceDaemon start(Supplier<Boolean> isCancelled,
Consumer<String> processStopped) throws ExecutionException {
final int daemonId = nextDaemonId.incrementAndGet();
//noinspection UnnecessaryToStringCall
LOG.info("starting Flutter device daemon #" + daemonId + ": " + toString());
LOG.info("starting Flutter device daemon #" + daemonId + ": " + toString(FlutterSettings.getInstance().isFilePathLoggingEnabled()));
// The mostly silent process handler reduces CPU usage of the daemon process.
final ProcessHandler process = new MostlySilentColoredProcessHandler(toCommandLine());

Expand Down Expand Up @@ -268,7 +271,7 @@ else if (attempts == DeviceDaemon.RESTART_ATTEMPTS_BEFORE_WARNING + 4) {
}
catch (java.util.concurrent.ExecutionException e) {
// This is not a user facing crash - we log (and no devices will be discovered).
FlutterUtils.warn(LOG, e.getCause());
FlutterUtils.warn(LOG, e, true);
}
}
}
Expand Down Expand Up @@ -311,8 +314,12 @@ private GeneralCommandLine toCommandLine() {

@Override
public String toString() {
return toString(true);
}

public @NotNull String toString(boolean showFullPath) {
final StringBuilder out = new StringBuilder();
out.append(command);
out.append(showFullPath ? command : command.substring(command.lastIndexOf(File.separatorChar) + 1));
if (!parameters.isEmpty()) {
out.append(' ');
out.append(Joiner.on(' ').join(parameters));
Expand Down Expand Up @@ -426,7 +433,7 @@ private static ImmutableList<FlutterDevice> removeDevice(Stream<FlutterDevice> o
}
}

private static final @NotNull Logger LOG = Logger.getInstance(DeviceDaemon.class);
private static final @NotNull Logger LOG = PluginLogger.createLogger(DeviceDaemon.class);

// If the daemon cannot be started, display a modal dialog with hopefully helpful
// instructions on how to fix the problem. This is a big problem; we really do
Expand Down
6 changes: 1 addition & 5 deletions src/io/flutter/sdk/FlutterSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,7 @@ public PubRoot createFiles(@NotNull VirtualFile baseDir, @Nullable Module module
}
}
catch (InterruptedException e) {
if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) {
LOG.warn(e);
} else {
LOG.warn(e.toString());
}
FlutterUtils.warn(LOG, e, true);
return null;
}

Expand Down