搜尋套件、儲存庫與 APP 分類

套件詳情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 項

原始碼儲存庫

使用此套件的專案