Joris Hermans
Joris Hermans

Reputation: 191

Logging box in observatory is empty, how can I get logging?

When I add the following code to my dart programme I expect to have some logging in observatory but instead it is empty.

void setupLogging() {
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((LogRecord rec) {
     print('${rec.level.name}: ${rec.time}: ${rec.message}');
  });
}

And then in some method:

log.fine('Databases are up and running');

observatory logging empty

Upvotes: 1

Views: 70

Answers (1)

Fox32
Fox32

Reputation: 13560

Simply using print doesn't work, but the dart:developer library contains a log function that you can use for that purpose.

It has the same arguments as used by the LogRecord from the logging package:

void log(String message,
                  {DateTime time,
                   int sequenceNumber,
                   int level: 0,
                   String name: '',
                   Zone zone,
                   Object error,
                   StackTrace stackTrace});

Upvotes: 1

Related Questions