パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.5.1

redux_logging

最新のアクションと状態を出力する Redux.dart ミドルウェア

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3580
いいね数
29
Pub ポイント
150

パッケージをインストール

flutter pub add redux_logging

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Redux_logging は、Redux.dart のためのミドルウェアであり、各アクションとその処理後の状態をログに記録します。開発者がステートの変更をデバッグするのを助けるために、アクションとそれらがアプリケーションステートに与える影響をリアルタイムで出力します。開発環境に最適で、ステートが時間とともにどのように進化するかの可視性を高めます。既存の Redux.dart セットアップとシームレスに統合され、Android、iOS、Web、macOS、Windows、Linux を含むすべての主要プラットフォームをサポートしています。

用途

  • デバッグ状態遷移
  • 開発中のアクションフローのモニタリング
  • 複雑なアプリでの状態変更の追跡
  • リ듀ーサーの論理を検証する
  • デバッグにおける開発者体験の向上

主な機能

  • 各ディスパッチ後にアクションと状態をログに記録します
  • Redux.dart との簡単な統合
  • クロスプラットフォーム対応
  • 最小限のパフォーマンスオーバーヘッド
  • 設定可能なログ出力動作

適している対象

  • Redux.dart を使用する開発者
  • 状態の透明性を重視するチーム
  • 複雑な状態管理を備えたアプリケーション
  • デバッグに注力するフロントエンド開発者
  • Redux パターンの学習または指導

注意事項

  • 本番ビルドには推奨されません
  • ログ出力が頻繁すぎるとパフォーマンスに影響する可能性があります
  • 高度な使用には手動構成が必要です
  • 基本的なコンソール出力のみ
  • 実行時以降にログを永続化しない

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

redux_logging

Build Status codecov

Connects a Logger to a Redux Store. Can also simply print the latest state / action changes.

Logs every Action that is dispatched to the Store, along with the current State.

By default, this class does not print anything to your console or send data to a web service, such as Fabric or Sentry. It simply logs entries to a Logger instance.

If you simply want to print the latest action and state to your console / terminal, create a new LoggingMiddleware.printer() and pass it to your Store upon creation.

If you want more control over where the logged data is sent, you can listen to your Logger's onRecord Stream.

Dart Versions

  • Dart 1 support: 0.1.x
  • Dart 2 Support: 0.2.x+
Simple Printing example

If you just want an easy way to print actions to your console / terminal as they are dispatched, use the new LoggingMiddleware.printer() factory.

Note: The LoggingMiddleware needs be the LAST middleware in the list.

import "package:redux/redux.dart";
import 'package:redux_logging/redux_logging.dart';

final store = new Store<int>(
  (int state, dynamic action) => state + 1,
  initialValue: 0,
  // Note the LoggingMiddleware should come last in the list of Middleware!
  middleware: [myOtherMiddleware, new LoggingMiddleware.printer()]
);

store.dispatch("Hi"); // prints {Action: "Hi", Store: 1, Timestamp: ...}
Example

If you only want to log actions to a Logger, and choose how to handle the output, use the default constructor.

import 'package:logging/logging.dart';
import "package:redux/redux.dart";
import 'package:redux_logging/redux_logging.dart';

// Create your own Logger
final logger = new Logger("Redux Logger");

// Pass it to your Middleware
final middleware = new LoggingMiddleware(logger: logger);
final store = new Store<int>(
  (int state, dynamic action) => state + 1,
  initialState: 0,
  middleware: [middleware],
);

// Note: One quirk about listening to a logger instance is that you're
// actually listening to the Singleton instance of *all* loggers.
logger.onRecord
  // Filter down to [LogRecord]s sent to your logger instance
  .where((record) => record.loggerName == logger.name)
  // Print them out (or do something more interesting!)
  .listen((loggingMiddlewareRecord) => print(loggingMiddlewareRecord));
Formatting the log message

This library includes two formatters out of the box:

  • LoggingMiddleware.singleLineFormatter
  • LoggingMiddleware.multiLineFormatter

You can optionally control the format of the message that will be logged by implementing your own MessageFormatter and passing it to the LoggingMiddleware constructor. It is a simple function that takes three parameters: the State, Action, and Timestamp.

Formatting Example
import "package:redux/redux.dart";
import 'package:redux_logging/redux_logging.dart';

// Create a formatter that only prints out the dispatched action
String onlyLogActionFormatter<State>(
  State state,
  dynamic action,
  DateTime timestamp,
) {
  return "{Action: $action}";
}

// Create your middleware using the formatter.
final middleware = new LoggingMiddleware(formatter: onlyLogActionFormatter);

// Add the middleware with your formatter to your Store
final store = new Store<int>(
  (int state, dynamic action) => state + 1,
  initialState: 0,
  middleware: [middleware],
);

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト