How to print to log in Flutter?
4,183
Based on Flutter Doc, the logging view displays events from the Dart runtime, application frameworks (like Flutter), and application-level logging events.By default, the logging view shows:
- Garbage collection events from the Dart runtime
- Flutter framework events, like frame creation events
-
stdout
andstderr
from applications - Custom logging events from applications
Refer the Debugging Flutter Applications Programmatically Doc. You can use:
stderr.writeln('print me');
Or
import 'dart:developer' as developer;
void main() {
developer.log('log me', name: 'my.app.category');
developer.log('log me 1', name: 'my.other.category');
developer.log('log me 2', name: 'my.other.category');
}
Or
import 'dart:convert';
import 'dart:developer' as developer;
void main() {
var myCustomObject = ...;
developer.log(
'log me',
name: 'my.app.category',
error: jsonEncode(myCustomObject),
);
}
to log from your app.
Comments
-
Jack621311 over 1 year
I wanted to print a log statement onto any LogCat console (Verbose, Debug, etc) but I can't seem to find a way to do it.
The
print()
ordebugPrint()
doesn't seem to work, or better yet should I say I don't know where they are printing.Also, for some reason, the LogCat console is saying "No connected devices" and "No debuggable process" even though I have the emulator running in background and the files are executing on the emulator perfectly.
-
Hitesh Sahu over 2 yearsI have created a logger for flutter: stackoverflow.com/a/68595809/2252113. feel free to use it.
-