SourceHorizon/logger

weird behaviour while using logger with workmanager

milindgoel15 opened this issue · 3 comments

Hi,

I wanted to log a message based on the result of the work manager job in my app. So on success run, it shows ran successfully or error in case of failure run. So I checked in the case of success run and this is what i got in the logs:

console logs
I/flutter (10449): │ #0   callbackDispatcher.<anonymous closure> (package:weatherwise/main.dart:97:18)
main.dart:97
I/flutter (10449): │ #1   <asynchronous suspension>
I/flutter (10449): │ 💡 Scheduled job ran successfully!

it throw some exception of some kind?

This is my work manager code with logger:

code
  Workmanager().executeTask((task, inputData) async {
    switch (task) {
      case "currentWeather":
        final sharedPreference = await SharedPreferences.getInstance();

        try {
          final weatherResponse = await WidgetService()
              .getWidgetWeather(sharedPreference.getString('activeKey') ?? "");

          WidgetService().updateWidget(weatherResponse);
          logger.i("Scheduled job ran successfully!");
        } catch (e) {
          logger.e(
            'Error occurred while fetching weather:',
            error: e,
          );
        }

        return Future.value(true);
    }
    return Future.value(true);
  });

Hi, I figured that you didn't configure a custom printer and are therefore using the default printer (PrettyPrinter) for the logger.

PrettyPrinter has by default a methodCount of 2, which means that every log, even non errors, is accommodated by a stack trace.

You can disable that feature by providing your own printer instance with a methodCount of 0:

var logger = Logger(
  printer: PrettyPrinter(methodCount: 0),
);

Oh, thats why.

Also, can we disable the rectangle border as well? (The lines around the log messages)

Sure, just set noBoxingByDefault: true.