Log<St> class

Connects a Logger to the Redux Store. Every action that is dispatched will be logged to the Logger, along with the new State that was created as a result of the action reaching your Store's reducer.

By default, this class does not print anything to your console or to a web service, such as Fabric or Sentry. It simply logs entries to a Logger instance. You can then listen to the Logger.onRecord Stream, and print to the console or send these actions to a web service.

Example: To print actions to the console as they are dispatched:

var store = Store(
  initialValue: 0,
  actionObservers: [Log.printer()]);

Example: If you only want to log actions to a Logger, use the default constructor.

// Create your own Logger and pass it to the Observer.
final logger = new Logger("Redux Logger");
final stateObserver = Log(logger: logger);

final store = new Store<int>(
  initialState: 0,
  stateObserver: [stateObserver]);

// 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((LogRecord) => print(LogRecord));
Implemented types

Constructors

Log({Logger? logger, Level level = Level.INFO, MessageFormatter<St> formatter = singleLineFormatter})
Logs actions to the given Logger, and does not print anything to the console.
Log.printer({Logger? logger, Level level = Level.INFO, MessageFormatter<St> formatter = singleLineFormatter})
Logs actions to the console.
factory

Properties

formatter MessageFormatter<St>
A function that formats the String for printing
final
hashCode int
The hash code for this object.
no setterinherited
level → Level
The log Level at which the actions will be recorded
final
logger → Logger
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
observe(ReduxAction<St> action, int dispatchCount, {required bool ini}) → void
If ini==true this is right before the action is dispatched. If ini==false this is right after the action finishes.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

multiLineFormatter(dynamic state, ReduxAction action, bool ini, int dispatchCount, DateTime timestamp) String
A formatter that puts each attribute on it's own line.
singleLineFormatter(dynamic state, ReduxAction action, bool? ini, int dispatchCount, DateTime timestamp) String
A simple formatter that puts all data on one line.
verySimpleFormatter(dynamic state, ReduxAction action, bool ini, int dispatchCount, DateTime timestamp) String
A very simple formatter that writes only the action.