Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: logger

I'm using https://pub.dartlang.org/packages/logging, but it doesn't display anything to my log. This is my code:

class Test {

  final Logger log = new Logger('testLogger');

  Future<String> join() async {
    try {
      return await func();
    } on Exception catch (e) {
        log.severe('access denied!');
        return null;
  }

}
like image 507
Little Monkey Avatar asked Feb 11 '19 10:02

Little Monkey


People also ask

What is the best logging tool in flutter?

Logging options in Flutter In Flutter there are different sets of options available for logging, one of which is FLog. FLog is an advanced logging framework that provides a quick & simple logging solution. FLog is written in Dart and provides many of the advanced features needed for logging.

What is flog logging in flutter?

We all know that feeling of going through thousands and thousands of lines of log messages without any useful info at all. In Flutter there are different sets of options available for logging, one of which is FLog. FLog is an advanced logging framework that provides a quick & simple logging solution.

How to log and print messages in flutter?

Generally logging messages in flutter can be done using 2 ways. 1. Using stdout & stderr. Generally printing a message on the console screen is done using the print () method by importing ‘dart:io’ & by invoking stdout & stderr.

How to use developer log function in flutter?

So to use developer.log function in flutter print to console or devtool, you need to just import ‘dart:developer’ as devlog & now use it as shown below ( devlog.log (“This is Log message from developer log method”); ) output: developer.log console log will only be show in devTool


1 Answers

You need to register a log reporter.

From https://pub.dartlang.org/packages/logging

main() {
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((LogRecord rec) {
    debugPrint('${rec.level.name}: ${rec.time}: ${rec.message}');
  });
  runApp(...);
}

You can have log reporters that write to a file or to some logging server, ...

like image 118
Günter Zöchbauer Avatar answered Oct 07 '22 19:10

Günter Zöchbauer