initializeLogger function

void initializeLogger(
  1. Level level
)

Helper function which initializes the Logger to listen for log events and print them if they meet level or higher (more severe).

This function should be called only once.

Usage:

initializeLogger(Level.INFO);
log.fine("this message won't print");
log.warning("this message will print");

Implementation

void initializeLogger(Level level) {
  if (_loggerInitialized) {
    Logger("initializeLogger()").warning(
        "Attempted to initialize the logger after it was already initialized.");
    return;
  }

  logLevel = level;

  Logger.root.onRecord.listen((LogRecord rec) {
    stdout.writeln('(${rec.time}:)[${rec.loggerName}]${rec.level.name}: ${rec.message}');
  });

  _loggerInitialized = true;
}