55 */
66package io .flutter .logging ;
77
8+ import com .intellij .openapi .application .ApplicationManager ;
89import com .intellij .openapi .application .PathManager ;
10+ import com .intellij .openapi .diagnostic .LogLevel ;
911import com .intellij .openapi .diagnostic .Logger ;
12+ import io .flutter .settings .FlutterSettings ;
1013import org .jetbrains .annotations .NotNull ;
1114
1215import java .io .File ;
1619
1720public 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}
0 commit comments