Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt logger to be more dartly #9

Open
wrozwad opened this issue Aug 15, 2019 · 2 comments
Open

Adapt logger to be more dartly #9

wrozwad opened this issue Aug 15, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@wrozwad
Copy link

wrozwad commented Aug 15, 2019

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:
flutter/flutter-intellij#2200 (comment)
image

@haarts haarts added the enhancement New feature or request label Dec 4, 2019
@haarts
Copy link
Collaborator

haarts commented Dec 10, 2019

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.

@KlausJokisuo
Copy link

KlausJokisuo commented Mar 11, 2020

@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?

timmaffett pushed a commit to timmaffett/logger that referenced this issue Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants