SourceHorizon / logger

Small, easy to use and extensible logger which prints beautiful logs.
https://pub.dev/packages/logger
MIT License
222 stars 39 forks source link

weird behaviour while using logger with workmanager #42

Closed milindgoel15 closed 1 year ago

milindgoel15 commented 1 year ago

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 ```console I/flutter (10449): │ #0 callbackDispatcher. (package:weatherwise/main.dart:97:18) main.dart:97 I/flutter (10449): │ #1 I/flutter (10449): │ 💡 Scheduled job ran successfully! ```

it throw some exception of some kind?

This is my work manager code with logger:

code ```dart 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); }); ```
Bungeefan commented 1 year ago

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),
);
milindgoel15 commented 1 year ago

Oh, thats why.

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

Bungeefan commented 1 year ago

Sure, just set noBoxingByDefault: true.