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 and stderr 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.

Share:
4,183
Jack621311
Author by

Jack621311

Wanna play minecraft? xD

Updated on December 19, 2022

Comments

  • Jack621311
    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() or debugPrint() 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.