I use log
from import 'dart:developer';
but it seems that it does not print anything when I use from unit test.
What should I use for logging in both test and dev environments but not in production?
Thanks.
you can simply use print('whatever you want to print') same as console. log() in javascript. for more info you can check here. Save this answer.
To avoid this, use debugPrint() , from Flutter's foundation library. This is a wrapper around print that throttles the output to a level that avoids being dropped by Android's kernel. The other option for application logging is to use the dart:developer log() function.
dart:developer
only works in debug environments where the Dart vm service is available. As such, launching the unit tests with the debugger attached should work fine. It programmatically interacts with the Dart VM and debugger, so if those aren't attached it won't work properly.
However, logging can be very helpful for production environments as well, so I’d recommend migrating to a different package for a robust logging service across environments. dart:developer
is not designed as a logger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With