Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion src/io/flutter/logging/PluginLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package io.flutter.logging;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.LogLevel;
import com.intellij.openapi.diagnostic.Logger;
import io.flutter.settings.FlutterSettings;
import org.jetbrains.annotations.NotNull;

import java.io.File;
Expand All @@ -16,7 +18,10 @@

public class PluginLogger {
private static final String LOG_FILE_NAME = "flutter.log";

// This handler specifies the logging format and location.
private static final FileHandler fileHandler;

static {
final String logPath = PathManager.getLogPath();
try {
Expand All @@ -30,8 +35,22 @@ public class PluginLogger {
fileHandler.setFormatter(new SimpleFormatter());
}

// Add the handler to the root logger so that all classes within `io.flutter` log to the file correctly. We can also update the log level
// of all classes at once by changing the root logger level.
private static final java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("io.flutter");

static {
rootLogger.addHandler(fileHandler);
updateLogLevel();
FlutterSettings.getInstance().addListener(PluginLogger::updateLogLevel);
}

private static void updateLogLevel() {
final Logger rootLoggerInstance = Logger.getInstance("io.flutter");
rootLoggerInstance.setLevel(FlutterSettings.getInstance().isVerboseLogging() ? LogLevel.ALL : LogLevel.INFO);
}

public static @NotNull Logger createLogger(@NotNull Class<?> logClass) {
java.util.logging.Logger.getLogger(logClass.getName()).addHandler(fileHandler);
return Logger.getInstance(logClass.getName());
}
}
8 changes: 2 additions & 6 deletions src/io/flutter/run/daemon/DaemonApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType
else if (outputType.equals(ProcessOutputTypes.STDOUT)) {
final String text = event.getText();

if (FlutterSettings.getInstance().isVerboseLogging()) {
LOG.info("[<-- " + text.trim() + "]");
}
LOG.debug("[<-- " + text.trim() + "]");

stdoutParser.appendOutput(text);

Expand Down Expand Up @@ -305,9 +303,7 @@ private static void sendCommand(String json, ProcessHandler handler) {
stdin.write(json);
stdin.write("]\n");

if (FlutterSettings.getInstance().isVerboseLogging()) {
LOG.info("[--> " + json + "]");
}
LOG.debug("[--> " + json + "]");

if (stdin.checkError()) {
LOG.warn("can't write command to Flutter process due to error: " + json);
Expand Down
Loading