debugPrint and the power of hiding and customizing your logs in Dart
When developing and debugging software, we usually log some kind of messages to assert its behavior. In Dart, we can do this using the print :
This output doesn’t provide us with much information. Besides the printed message and a flutter
label, we don’t have an indication of the app name or a timestamp of when the message was printed.
Furthermore, if you use the command flutter logs
you will see the output of the print
function in all applications you have installed in the phone/emulator. This means that even if the app is in release mode
, it will still be printed in the terminal.
This poses two problems:
- Any print statement can be potentially seen by any user of the app, which can be a problem if we print sensitive information.
- If we are monitoring your app using
flutter logs
we won’t be able to distinguish between our apps and other flutter apps installed in your phone.