logger icon indicating copy to clipboard operation
logger copied to clipboard

Adapt logger to be more dartly

Open wrozwad opened this issue 6 years ago • 2 comments
trafficstars

I think that this library should me more Dart like in place of Android like. So for me there will be better to use Dart Levels (package:logging/logging.dart) in place of android levels.

I made some mapping from Android to dart logging levels:

library Levels Native Levels
nothing ALL
--- FINEST
--- FINER
verbose FINE
debug CONFIG
info INFO
warning WARNING
error SEVERE
wtf SHOUT

And I implemented it in custom LogOutput:

import 'dart:developer';

import 'package:logger/logger.dart';
import 'package:logging/logging.dart' as dartLog;

class PrettierConsoleOutput extends LogOutput {
  final _lvlMapping = {
    Level.nothing: dartLog.Level.ALL.value,
    Level.verbose: dartLog.Level.FINE.value,
    Level.debug: dartLog.Level.CONFIG.value,
    Level.info: dartLog.Level.INFO.value,
    Level.warning: dartLog.Level.WARNING.value,
    Level.error: dartLog.Level.SEVERE.value,
    Level.wtf: dartLog.Level.SHOUT.value,
  };

  @override
  void output(OutputEvent event) {
    for (var line in event.lines) {
      log(line, level: _lvlMapping[event.level]);
    }
  }
}

It gives us much better log filtering and you can easly add colors to them: https://github.com/flutter/flutter-intellij/issues/2200#issuecomment-439417969 image

wrozwad avatar Aug 15 '19 11:08 wrozwad

I like that the IDEs (Android Studio too) has support for this. Especially since colouring of console output in the IDEs doesn't work. This goes on my todo list.

haarts avatar Dec 10 '19 09:12 haarts

@sosite I'm unable to produce coloring on Android Studio output.

      dartLog.Level.LEVELS.forEach((level) {
        developer.log('Test!', level: level.value);
      });

image

Any tips?

KlausJokisuo avatar Mar 11 '20 07:03 KlausJokisuo