搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目