r/FlutterDev • • Oct 19 '26

Tooling Migrate debugPrint and print calls in a Flutter or Dart package to use package:logging

Faced with the problem of migrating debugPrint/print methods of flutter and dart files across multiple packages with large number of files & lines.

Created & pubslihed print_to_log package to automate the the convertion. Used it across 20+ internal packages successfully. It uses analyzer package to parse each file into source tree & walks that tree and then do sugical edits by not touching any other parts.

The package shall be used as a CLI tool or as a dev dependency package.

Github : https://github.com/selvan/print_to_log

Pub.dev: https://pub.dev/packages/print_to_log

It's MIT license.

4 Upvotes

4 comments sorted by

1

u/ObjectiveAddress3051 Oct 21 '26

Using the analyzer AST for surgical edits instead of regex is the right call for this. Worth pairing it with the avoid_print lint in analysis_options.yaml so new print calls don't creep back in after the migration. Which level does debugPrint map to by default, FINE or INFO?

1

u/phone_radio_tv Oct 21 '26

defaults to log.fine

1

u/[deleted] Oct 19 '26

[removed] — view removed comment

0

u/phone_radio_tv Oct 19 '26

Comes with --dry-run flag, formating is off by default, if required shall be used with --format flag.