How to print() to logs in the release mode in Flutter?
There are several ways of doing it:
-
Use the following command
flutter logs
-
Use
logger
package.The default implementation (DevelopmentFilter) shows all logs with level >= Logger.level while in debug mode. In release mode all logs are omitted.
In order to show all logs even in release mode, create your own
LogFilter
like this:class MyFilter extends LogFilter { @override bool shouldLog(LogEvent event) { return true; } }
Usage:
void foo() { var logger = Logger(filter: MyFilter()); logger.d('message'); }
-
Use
print
statement (not sure if this works on web)
DaveBound
Updated on December 06, 2022Comments
-
DaveBound over 1 year
My web app has a problem that only manifests in profile and release builds (a widget is not rendering properly, producing only gray). I want to add some print() statements to help figure out what the problem is, but print() doesn't log anything to VSCode debug output window in profile/release builds.
Any ideas how to fix that?
What other techniques can I use to diagnose release-only problems?
Thx