Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Logging your app's print statements to a local file for later processing.
import 'dart:async';
import 'dart:core';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
void main() => runLoggedApp(App());
// View the log with:
// adb shell run-as <your-android-package> cat /data/data/<your-android-package>/app_flutter/log.txt
void runLoggedApp(Widget app, [String filename = 'log.txt']) async {
final log =
File(p.join((await getApplicationDocumentsDirectory()).path, filename))
.openWrite(mode: FileMode.append);
runZoned(() {
}, zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
log.writeln('${} | $line');
parent.print(zone, line);
class App extends StatelessWidget {
Widget build(BuildContext context) {
return Container();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment