How to print() to logs in the release mode in Flutter?

567

There are several ways of doing it:

  1. Use the following command

    flutter logs
    
  2. 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');
    }
    
  3. Use print statement (not sure if this works on web)

Share:
567
DaveBound
Author by

DaveBound

Updated on December 06, 2022

Comments

  • DaveBound
    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