Lightweight modular logger for Dart and Flutter
Trackit is a modular lightweight logger for Dart and Flutter applications. To achieve the functionality you need, you< can use ready-made modules described below, or write similar modules manually.
The Trackit logging system is designed with the DRY and KISS principles in mind. By adding only the packages you need to dependencies, you can eliminate unused code and functionality as much as possible.
For example, to output and format logs to the console or other, you can only connect the trackit_console
package.
If you want to store the latest log entries in memory for further processing (displaying on the screen,
transferring from the tester to the developer, etc.), use the trackit_history
package.
Trackit is designed as a lightweight logger with the ability to expand and fully customize. Below is a list of ready-made modules that can be used together with Trackit to obtain the necessary functionality. You can use them as is, or expand them if necessary to suit your needs.
Package | Version | Description |
---|---|---|
trackit | The basic core of the logger, used as a dependency of all its extensions. It cannot accumulate and output logs. In its pure form it should be used only as a base for extensions. |
|
trackit_console | Logger extension used to format and output logger events to the console. . |
|
trackit_history | Trackit logger extension for storing logs in memory. |
The logging system is an auxiliary module. It should not be a combine and be able to do everything. The basic logger module should only be able to generate an event and send it further.
To display, process and collect logger events, it is necessary to use separate modules, which are necessary in each specific case.
Each application has its own requirements for log processing. Some output them to the console, some send them to the error collection system (Firebase Crashlytics, Sentry, etc), some display them in the interface, and perhaps all at the same time!
trackit
- READMEtrackit_console
- READMEtrackit_history
- README- How to use with BLoC
- How to use with Riverpod
The example code demonstrating the capabilities of the Trackit logger ecosystem can be viewed in the example
- ✅ Create full example app
- ✅ Test it in real projects!
- Write docs (and this README) (How use it with routing, blocs etc...)
- ❗️ Create contributing rules
- Add package for work with Dio
- ... any more
- Publish 1.0.0 version)
Create observer:
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:trackit/trackit.dart';
class AppBlocObserver extends BlocObserver {
static final _log = Trackit.create('BlocObserver');
static AppBlocObserver? _instance;
factory AppBlocObserver.instance() => _instance ??= const AppBlocObserver._();
const AppBlocObserver._();
@override
void onError(BlocBase<dynamic> bloc, Object error, StackTrace stackTrace) {
super.onError(bloc, error, stackTrace);
_log.error('Unhandled bloc exception', error, stackTrace);
}
}
set it is BLoC observer:
import 'package:flutter_bloc/flutter_bloc.dart';
Bloc.observer = AppBlocObserver.instance();
Create observer:
import 'package:riverpod/riverpod.dart';
import 'package:trackit/trackit.dart';
class RiverpodObserver extends ProviderObserver {
static final _log = Trackit.create('RiverpodObserver');
@override
void providerDidFail(
ProviderBase<Object?> provider,
Object error,
StackTrace stackTrace,
ProviderContainer container,
) {
_log.error('Unhandled riverpod exception', error, stackTrace);
}
@override
void didUpdateProvider(
ProviderBase<Object?> provider,
Object? previousValue,
Object? newValue,
ProviderContainer container,
) {
_log.debug(
'${provider.name ?? provider.runtimeType} provide new value $newValue');
}
}
set it is Riverpod observer:
import 'package:flutter/material.dart';
import 'package:riverpod/riverpod.dart';
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return ProviderScope(
observers: [RiverpodObserver()],
child: const MaterialApp(home: Home()),
);
}
}