simc / logger

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

feature/setting-begin-stack-trace-index #81

Closed defuncart closed 3 years ago

defuncart commented 3 years ago

Adds the setting stackTraceBeginIndex (the index which to begin the stack trace at) to PrettyPrinter. This can be useful if, for instance, Logger is wrapped in another class and you wish to remove these wrapped calls from stack trace.

Looking forward to your feedback :)

haarts commented 3 years ago

If I understand it correctly this is the counterpart of methodCount?

I also need to commend you on the excellent commits, that alone makes me want to merge it. ;)

defuncart commented 3 years ago

@haarts stackTraceBeginIndex is the index to begin the stack trace at, while methodCount is the number of methods that should be shown from the stack trace.

So, for instance

class MyLogger {
  final _logger = Logger(
    printer: PrettyPrinter(
      stackTraceBeginIndex: 1,
    ),
  );

  void debug(dynamic obj) => _logger.d(obj);
}
void main(){
  MyLogger().debug('Hello, World!');
}

In the console something like

main.dart:2 MyLogger().debug('Hello, World!');

would be printed out. Without stackTraceBeginIndex set to 1, something along the lines of

my_logger.dart:7 void debug(dynamic obj) => _logger.d(obj);
main.dart:2 MyLogger().debug('Hello, World!');

would be printed as the stack trace.