katana_logger 2.0.26 katana_logger: ^2.0.26 copied to clipboard
Base package for logging app performance and access status. Additional packages can be installed to use Firebase Analytics, etc.
Katana Logger
[GitHub] | [YouTube] | [Packages] | [Twitter] | [Threads] | [LinkedIn] | [mathru.net]
Provides the ability to collect application logs for Katana/Masamune Framework.
Installation #
Import the following packages.
flutter pub add katana_logger
Implementation #
Advance preparation #
Be sure to place the LoggerAdapterScope
widget near the root of the app.
Pass a LoggerAdapter such as RuntimeLoggerAdapter
as the adapter parameter.
// main.dart
import 'package:flutter/material.dart';
import 'package:katana_logger/katana_logger.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return LoggerAdapterScope(
adapter: const RuntimeLoggerAdapter(),
child: MaterialApp(
home: const LoggerPage(),
title: "Flutter Demo",
theme: ThemeData(
primarySwatch: Colors.blue,
),
),
);
}
}
Creating Logger Objects #
To perform logging, first create a Logger
and keep it somewhere.
This Logger
object actively performs the following logging
send
、sendRawData
:Records log events.trace
:Records trace events.
Since Logger
inherits from ChangeNotifier, it is possible to monitor updates by using addListener
, riverpod's ChangeNotifierProvider
, etc.
It is also possible to check the logs recorded with the logList
method.
// logger_page.dart
import 'package:flutter/material.dart';
import 'package:katana_logger/katana_logger.dart';
class LoggerPage extends StatefulWidget {
const LoggerPage({super.key});
@override
State<StatefulWidget> createState() => LoggerPageState();
}
class LoggerPageState extends State<LoggerPage> {
final logger = Logger();
List<LogValue> _values = [];
@override
void initState() {
super.initState();
logger.addListener(_handledOnUpdate);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_handledOnUpdate();
}
Future<void> _handledOnUpdate() async {
_values = await logger.logList();
setState(() {});
}
@override
void dispose() {
super.dispose();
logger.removeListener(_handledOnUpdate);
logger.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("App Demo")),
body: ListView(
children: [
..._values.map(
(e) => ListTile(
title: Text(e.name),
subtitle: Text(e.dateTime.toIso8601String()),
),
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
logger.sendRawData("test", parameters: {"count": 5});
},
child: const Icon(Icons.add),
),
);
}
}
GitHub Sponsors #
Sponsors are always welcome. Thank you for your support!