super_logging 0.2.0 super_logging: ^0.2.0 copied to clipboard
The usual dart logging module with superpowers!
Super Logging #
The usual dart logging module with superpowers!
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.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.
)
},
// [optional] automatically turn off sentry/file logging during debug mode.
bool considerDebugMode: true,
)
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!
If you pass a function to the run
argument,
super logging will register hooks for FlutterError.onError
and use runZoned()
to catch un-caught errors.
import 'package:super_logging/super_logging.dart';
import 'package:logging/logging.dart';
final _logger = Logger("main");
main() async {
await SuperLogging.init(
run: () {
runApp(Main()); // `Main` is the root widget
}
);
}
This is disabled if the app is running in debug mode, and considerDebugMode
is set to true