Skip to content

Commit 447759a

Browse files
authored
Change log level in PluginLogger for verbose logging (#8548)
This will enable debug-level logs to be seen in our log file when verbose logging is enabled. Addresses #8519
1 parent 6f3f6b9 commit 447759a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/io/flutter/logging/PluginLogger.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*/
66
package io.flutter.logging;
77

8+
import com.intellij.openapi.application.ApplicationManager;
89
import com.intellij.openapi.application.PathManager;
10+
import com.intellij.openapi.diagnostic.LogLevel;
911
import com.intellij.openapi.diagnostic.Logger;
12+
import io.flutter.settings.FlutterSettings;
1013
import org.jetbrains.annotations.NotNull;
1114

1215
import java.io.File;
@@ -16,7 +19,10 @@
1619

1720
public class PluginLogger {
1821
private static final String LOG_FILE_NAME = "flutter.log";
22+
23+
// This handler specifies the logging format and location.
1924
private static final FileHandler fileHandler;
25+
2026
static {
2127
final String logPath = PathManager.getLogPath();
2228
try {
@@ -30,8 +36,25 @@ public class PluginLogger {
3036
fileHandler.setFormatter(new SimpleFormatter());
3137
}
3238

39+
// 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
40+
// of all classes at once by changing the root logger level.
41+
private static final java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("io.flutter");
42+
43+
static {
44+
rootLogger.addHandler(fileHandler);
45+
// This check prevents trying to access settings in test context.
46+
if (ApplicationManager.getApplication() != null) {
47+
updateLogLevel();
48+
FlutterSettings.getInstance().addListener(PluginLogger::updateLogLevel);
49+
}
50+
}
51+
52+
private static void updateLogLevel() {
53+
final Logger rootLoggerInstance = Logger.getInstance("io.flutter");
54+
rootLoggerInstance.setLevel(FlutterSettings.getInstance().isVerboseLogging() ? LogLevel.ALL : LogLevel.INFO);
55+
}
56+
3357
public static @NotNull Logger createLogger(@NotNull Class<?> logClass) {
34-
java.util.logging.Logger.getLogger(logClass.getName()).addHandler(fileHandler);
3558
return Logger.getInstance(logClass.getName());
3659
}
3760
}

src/io/flutter/run/daemon/DaemonApi.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType
143143
else if (outputType.equals(ProcessOutputTypes.STDOUT)) {
144144
final String text = event.getText();
145145

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

150148
stdoutParser.appendOutput(text);
151149

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

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

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

0 commit comments

Comments
 (0)