super_logging 0.0.2 copy "super_logging: ^0.0.2" to clipboard
super_logging: ^0.0.2 copied to clipboard

outdated

The usual dart logging module with superpowers!

Super Logging #

The usual dart logging module with superpowers!

Sponsor

pub package

This will log to

  • stdout
  • disk
  • sentry.io

How do I use this? #

import 'package:super_logging/super_logging.dart';  // you only need this import for initialize
import 'package:logging/logging.dart';  // this is the regular dart module

final _logger = Logger("main");

main() async {
  // you must initalize before using the logger!
  await SuperLogging.instance.init();
  
  _logger.info("hello!");
}

This will log to stdout by default. Use may also choose to :-

Use sentry.io #

This module can upload errors to sentry.io if you want.

(Errors can be logged by passing errors like so: _logger.fine(msg, e, trace);)

await SuperLogging.init(
  // Passing this will enable sentry uploads.
  sentryDsn: "YOUR_SENTRY_DSN",

  // [optional] Has auto retry of uploads built right in!
  sentryAutoRetryDelay: Duration(seconds: 5),
  
  // [optional] Get current user info, which will be sent to sentry.
  // This appears in their web gui.
  getCurrentUser: (deviceInfo) {
    return User(
      username: "john",
      extras: deviceInfo,  // contains valuable info like device manufacturer, model etc.
    )
  },
)

Use the disk #

await SuperLogging.init(
  // Passing this will enable logging to the disk.
  // New log files are created every day.
  String logFileDir: "LOGGING_DIRECORY",

  // This controls the max no of log files inside [logFileDir].
  // This prevents log files blowing up.
  // Older log files are deleted automatically.
  int maxLogFiles: 10,
)

Can I log uncaught errors? #

Yes! just do the following, along with SuperLogger.init()

import 'package:super_logging/super_logging.dart';
import 'package:logging/logging.dart';

final _logger = Logger("main");

main() async {
  await SuperLogging.instance.init();

  // catch all errors from flutter
  FlutterError.onError = (errorDetails) {
    _logger.fine(
      "error caught inside `FlutterError.onError()`",
      errorDetails.exception,
      errorDetails.stack,
    );
  };

  runZoned(() {
    runApp(Main());  // `Main` is the root widget
  }, onError: (e, trace) {
    _logger.fine("error caught inside `main()` run zone", e, trace);
  }); 
}
0
likes
0
pub points
20%
popularity

Publisher

unverified uploader

The usual dart logging module with superpowers!

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

device_info, flutter, intl, logging, package_info, path, sentry

More

Packages that depend on super_logging