skip to Main Content

I am using the package logger. I want to write all the logs printed in the console to a separate file(in release mode too). I want to be able to download this file at anytime from the app. How do I do it?

2

Answers


  1. class ConsoleOutput extends LogOutput {
      @override
      void output(OutputEvent event) {
        for (var line in event.lines) {
          print(line);
        }
      }
    }

    enter code here

    Login or Signup to reply.
  2. import 'package:flutter/material.dart';
    import 'package:logger/logger.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      // Create a logger instance
      final Logger logger = Logger();
    
      @override
      Widget build(BuildContext context) {
        logger.d('Debug message');
        logger.i('Info message');
        logger.w('Warning message');
        logger.e('Error message');
    
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text('Logger Example'),
            ),
            body: Center(
              child: Text('Check the log file for messages'),
            ),
          ),
        );
      }
    }
    
    
    final logger = Logger(
      printer: PrettyPrinter(
        methodCount: 0,
        errorMethodCount: 8,
        lineLength: 120,
        colors: true,
        printEmojis: true,
        printTime: false,
      ),
      output: MultiOutput([
        ConsoleOutput(),
        FileOutput(),
      ]),
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search