Pakete, Repositories und App-Kategorien suchen

Paketdetailsv0.5.1

redux_logging

Redux.dart-Middleware, der die letzte Aktion und den letzten Zustand ausgibt

AndroidiOSWebmacOSWindowsLinux
30-Tage-Downloads
3580
Likes
29
Pub-Punkte
150

Paket installieren

flutter pub add redux_logging

Paketübersicht

Aus öffentlichen Paketdaten erstellte Orientierung.

Redux_logging ist ein Middleware für Redux.dart, der jede Aktion und den resultierenden Zustand nach deren Verarbeitung protokolliert. Es hilft Entwicklern, Zustandsänderungen zu debuggen, indem es Echtzeit-Ausgaben von Aktionen und ihren Auswirkungen auf den Anwendungszustand bereitstellt. Ideal für Entwicklungsumgebungen, erhöht es die Sichtbarkeit darüber, wie sich der Zustand im Laufe der Zeit verändert. Das Paket integriert sich nahtlos in bestehende Redux.dart-Setup und unterstützt alle wichtigen Plattformen einschließlich Android, iOS, Web, macOS, Windows und Linux.

Anwendungsfälle

  • Debugging-Zustandsübergänge
  • Überwachung des Ablaufs von Aktionen während der Entwicklung
  • Zustandsänderungen in komplexen Apps verfolgen
  • Überprüfung der Reduzierlogik
  • Verbesserung der Entwicklererfahrung beim Debuggen

Hauptmerkmale

  • Protokolliert Aktionen und Zustand nach jeder Dispatch
  • Einfache Integration mit Redux.dart
  • Plattformübergreifende Unterstützung
  • Minimale Leistungsüberhead
  • Konfigurierbares Protokollierungsverhalten

Geeignet für

  • Entwickler, die Redux.dart verwenden
  • Teams, die Zustandstransparenz priorisieren
  • Anwendungen mit komplexer Zustandsverwaltung
  • Frontend-Entwickler, die sich auf Debugging konzentrieren
  • Redux-Muster lernen oder vermitteln

Hinweise

  • Nicht empfehlenswert für Produktionsbuilds
  • Kann die Leistung beeinträchtigen, wenn zu häufig protokolliert wird
  • Erfordert manuelle Konfiguration für erweiterte Verwendung
  • Beschränkt auf grundlegende Konsole-Ausgabe
  • Persistiert Protokolle nicht über die Laufzeit hinaus

Original-README

Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.

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],
);

Kategorien

Abhängigkeiten

Abhängigkeiten 2 Einträge

Quell-Repository

Projekte, die dieses Paket verwenden