🚧

logを出力するパッケージtalkerを試してみた。

2024/10/13に公開

マイナーなパッケージなのかな

ある日Xの投稿で見つけたFlutterでログを出すパッケージでみたことないのがあるのを思い出した。普段は、loggerを使っておりますが、talkerなるものがあるのが気になりました。

Advanced error handler and logger for dart and flutter apps
Log your app actions, catch and handle exceptions and errors, show alerts and share log reports
Show some ❤️ and star the repo to support the project!


dartとflutterアプリのための高度なエラーハンドラとロガー
アプリのアクションをログし、例外やエラーをキャッチして処理し、アラートを表示してログレポートを共有する。
プロジェクトをサポートするために、❤️、レポに星をつけてください!

⭐はつけておいた。


Motivation

🚀 The main goal of the project is provide ability to understand where the error occurs in a shortest possible time
✅ Compatible with any state managements
✅ Works with any crash reporting tool (Firebase Crashlytics, Sentry, custom tools, etc.)
✅ Logs UI output of Flutter app on the screen
✅ Allows sharing and saving logs history and error crash reports
✅ Displays alerts for UI exceptions.
✅ Built-in support for dio HTTP logs
✅ Built-in support for BLoC logs
✅ Built-in support for Riverpod logs
✅ Check all features


動機

🚀 プロジェクトの主な目標は、エラーがどこで発生したかを最短時間で理解する能力を提供することである。
✅ どの状態管理とも互換性がある
✅ 任意のクラッシュレポートツール(Firebase Crashlytics、Sentry、カスタムツールなど)と連動。
✅ FlutterアプリのUI出力をスクリーン上にログ出力
✅ ログ履歴とエラークラッシュレポートの共有と保存が可能
✅ UI例外のアラートを表示
✅ dio HTTPログの組み込みサポート
✅ BLoCログのビルトインサポート
Riverpodログのビルトインサポート
✅ 全ての機能をチェックする

Talker

Get Started
Follow these steps to the coolest experience in error handling

始める
以下のステップを踏んで、クールなエラー処理を体験してください。

Add dependency

dependencies:
  talker: ^4.4.1

Easy to use

You can use Talker instance everywhere in your app
Simple and concise syntax will help you with this

使いやすい
アプリのあらゆる場所でTalkerインスタンスを使用可能
シンプルで簡潔な構文が役立つ

import 'package:talker/talker.dart';

  final talker = Talker();

  /// Just logs
  talker.warning('The pizza is over 😥');
  talker.debug('Thinking about order new one 🤔');

  // Handling Exception's and Error's
  try {
    throw Exception('The restaurant is closed ❌');
  } catch (e, st) {
    talker.handle(e, st);
  }

  /// Just logs
  talker.info('Ordering from other restaurant...');
  talker.info('Payment started...');
  talker.good('Payment completed. Waiting for pizza 🍕');

example

logを出色するだけですがシンプルなデモアプリを作りました。表示、色の設定もできるので目的に合わせて試してみてください。

main.dart
import 'package:flutter/material.dart';
import 'package:talker/talker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

// instance
final talker = Talker();

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  
  void initState() {
    /// Just logs
    talker.info('Ordering from other restaurant...');
    talker.info('Payment started...');
    talker.warning('Payment completed. Waiting for pizza 🍕');
    super.initState();
  }

  void logger() {
    try {
      talker.debug('Thinking about order new one 🤔');
    } catch (e) {
      talker.warning('The pizza is over 😥');
      rethrow;
    }
  }

  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: logger,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

最後に

loggerのlikeは3234で、talkerのlikeは544ですが使ってみて色の変更が自由にできるのが気に入りまして自由度が高いので今後使ってみようと思いました。

Discussion