Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

developer.log does not print log in the test

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.

like image 346
mmdc Avatar asked Jun 20 '20 21:06

mmdc


People also ask

How do I print text in flutter?

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.

What is debugPrint in Dart?

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.


1 Answers

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.

like image 179
Pranav Kasetti Avatar answered Nov 09 '22 18:11

Pranav Kasetti