Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve logs from customer device in Flutter

I released my app and unfortunately some errors are happening on customer devices. I am trying to understand it for solving but I couldn't find a way to retrieve logs from a customer device.

Firebase Crashlytics is installed and logging uncaught exceptions but how can I retrieve all app-specific logs from device?

As I see iOS has added OSLogStore at iOS 15+ but there is no practical way to use from Flutter.

What solutions do you use to get recent logs from customer devices without telling your customer plugging their phones to Mac and running some commands on terminal. It can be automatic or remote controlled. Or from a button captioned "Send Device Logs".

like image 569
bahadir arslan Avatar asked Oct 20 '25 12:10

bahadir arslan


2 Answers

It's a common approach to create a centralized logging system which you only have to configure once on application startup. You can e.g. use dart's own logging package and configure it differently for debug and release builds.

import 'package:flutter/foundation.dart';

if(kReleaseMode){ 
   Logger.root.level = Level.INFO; // is also the default
   Logger.root.onRecord.listen((record) {
      // Write to a file, to a server or use something like crashlytics
      FirebaseCrashlytics.instance.log('${record.level.name}: ${record.time}: ${record.message}');
   });
} else {
   Logger.root.level = Level.ALL; 
   Logger.root.onRecord.listen((record) {
     print('${record.level.name}: ${record.time}: ${record.message}');
   });
}

Within your application, you can use it like this

final log = Logger('MyClassName');
log.info("Info message");
log.warning("Warning");

Of course, there is no need to use Crashlytics for that purpose. You can use any different remote logging solution or alternatively records everything to a file. For creating a file and writing to it, you can find more information in the documentation.

like image 86
JoRa Avatar answered Oct 23 '25 01:10

JoRa


Usually, I log few details on Firebase Crashlytics and other internal information(thorough) on AWS CloudWatch for both PROD & DEV environment.

like image 23
Pathik Patel Avatar answered Oct 23 '25 01:10

Pathik Patel