Skip to content

Commit dddce13

Browse files
authored
Move log level setup to initializer (#8564)
Fixes #8562 I'm realizing from this problem that logging at plugin startup may be tricky. E.g. with this change, I'm not totally sure what the setting will be at project initialization - probably with a level of INFO, or whatever is default in the IntelliJ logger. That's probably fine - if we are trying to log information from project startup, it would be reasonable to make the logs INFO or higher, as DEBUG level logs could be excluded even with a user setting of verbose.
1 parent 36ef16e commit dddce13

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/io/flutter/FlutterInitializer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import io.flutter.devtools.RemainingDevToolsViewFactory;
4040
import io.flutter.editor.FlutterSaveActionsManager;
4141
import io.flutter.logging.FlutterConsoleLogManager;
42+
import io.flutter.logging.PluginLogger;
4243
import io.flutter.module.FlutterModuleBuilder;
4344
import io.flutter.pub.PubRoot;
4445
import io.flutter.pub.PubRoots;
@@ -82,6 +83,10 @@ public class FlutterInitializer extends FlutterProjectActivity {
8283

8384
@Override
8485
public void executeProjectStartup(@NotNull Project project) {
86+
// This sets the correct log level and listens for future changes.
87+
PluginLogger.updateLogLevel();
88+
FlutterSettings.getInstance().addListener(PluginLogger::updateLogLevel);
89+
8590
log().info("Executing Flutter plugin startup for project: " + project.getName());
8691
// Disable the 'Migrate Project to Gradle' notification.
8792
FlutterUtils.disableGradleProjectMigrationNotification(project);

src/io/flutter/logging/PluginLogger.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ public class PluginLogger {
4242

4343
static {
4444
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-
}
5045
}
5146

52-
private static void updateLogLevel() {
47+
public static void updateLogLevel() {
5348
final Logger rootLoggerInstance = Logger.getInstance("io.flutter");
5449
rootLoggerInstance.setLevel(FlutterSettings.getInstance().isVerboseLogging() ? LogLevel.ALL : LogLevel.INFO);
5550
}

0 commit comments

Comments
 (0)