flutter_heyteacher_logger
A Flutter package that provides UI components and a model for viewing and managing application logs. This package is specifically designed for the Flutter HeyTeacher ecosystem.
Features
- Log Viewing & Filtering: A dedicated
LoggerScreento display, filter, and search through log messages. - Easy Access: A convenient
LoggerCardwidget for easy navigation to the logger screen. - Centralized Log Management: The
LoggerViewModelcaptures, configures, and stores logs in-memory. - Firebase Integration: Dynamically set log levels using Firebase Remote Config and forward structured logs to Firebase Analytics.
- UI Components: Includes widgets like
EnableLogsStorageChoiceCardandLoggingLevelDropDownMenuCardfor user interaction. - Routing: Pre-configured routing for the logger UI with
LoggingRouter. - Localization: Support for localizations via
FlutterHeyteacherLoggerLocalizations.
The components in this packages are implemented following Model-View-ViewModel (MVVM) architecture and Singleton pattern.
Getting started
Add the package to your pubspec.yaml:
dependencies:
flutter_heyteacher_logger:
This package relies on Firebase for remote configuration of log levels and for analytics. Ensure your Flutter project is correctly configured with Firebase.
Usage
Here is a basic example of how to use the logger UI components.
Initialization
First, initialize the LoggerViewModel. This is typically done at the start of your application.
import 'package:flutter_heyteacher_logger/flutter_heyteacher_logger.dart';
void main() async {
// ... other initializations
// Initialize LoggerViewModel
// It will start capturing logs based on the configuration.
await LoggerViewModel.instance.initialize();
runApp(MyApp());
}
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
.
.
.
@override
Widget build(BuildContext context) => MaterialApp.router(
.
.
.
localizationsDelegates: const [
FlutterHeyteacherLoggerLocalizations.delegate,
],
routerConfig: GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => const _MyHomePage(),
routes: [
LoggingRouter.builder(),
],
),
],
),
);
}
UI Components
To allow users to view logs, you can use the LoggerCard which navigates to the LoggerScreen on tap.
import 'package:flutter/material.dart';
import 'package:flutter_heyteacher_logger/flutter_heyteacher_logger.dart';
class SettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Settings'),
),
body: ListView(
children: [
// ... other settings
LoggerCard(''),
],
),
);
}
}
Logging Messages
To log messages from anywhere in your application, use the Logger instance from the LoggerViewModel.
import 'package:flutter_heyteacher_logger/flutter_heyteacher_logger.dart';
void doSomething() {
final logger = Logger('doSomething');
logger.info('This is an informational message.');
logger.warning('This is a warning message.');
try {
throw Exception('Something went wrong!');
} catch (e, s) {
logger.severe('An error occurred', e, s);
}
}