+0
Daily
5,710
stars
316
forks
57
watchers
162
prs
0
issues
42
releases
README
Logger for Redux
!redux-logger
Now maintained by LogRocket!
LogRocket is a production Redux logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay Redux actions + state, network requests, console logs, and see a video of what the user saw.
For more informatiom about the future of redux-logger, check out the discussion here.
Table of contents
Install
Usage
Options
Recipes
Log only in development
Log everything except actions with certain type
Collapse actions with certain type
Transform Immutable (without combineReducers)
Transform Immutable (with combineReducers)
Log batched actions
To Do
Known issues (with react-native only at this moment)
License
Install
npm i --save redux-logger
Typescript types are also available, via DefinitelyTyped:
npm i @types/redux-logger
Usage
javascript
import { applyMiddleware, createStore } from 'redux';
// Logger with default options
import logger from 'redux-logger'
const store = createStore(
reducer,
applyMiddleware(logger)
)
// Note passing middleware as the third argument requires redux@=3.1.0
Or you can create your own logger with custom options:
javascript
import { applyMiddleware, createStore } from 'redux';
import { createLogger } from 'redux-logger'
const logger = createLogger({
// ...options
});
const store = createStore(
reducer,
applyMiddleware(logger)
);
Note: logger must be the last middleware in chain, otherwise it will log thunk and promise, not actual actions (20).
Options
javascript
{
predicate, // if specified this function will be called before each action is processed with this middleware.
collapsed, // takes a Boolean or optionally a Function that receives getState function for accessing current store state and action object as parameters. Returns true if the log group should be collapsed, false otherwise.
duration = false: Boolean, // print the duration of each action?
timestamp = true: Boolean, // print the timestamp with each action?
level = 'log': 'log' | 'console' | 'warn' | 'error' | 'info', // console's level
colors: ColorsObject, // colors for title, prev state, action and next state: https://github.com/LogRocket/redux-logger/blob/master/src/defaults.jsL12-L18
titleFormatter, // Format the title used when logging actions.
stateTransformer, // Transform state before print. Eg. convert Immutable object to plain JSON.
actionTransformer, // Transform action before print. Eg. convert Immutable object to plain JSON.
errorTransformer, // Transform error before print. Eg. convert Immutable object to plain JSON.
logger = console: LoggerObject, // implementation of the console API.
logErrors = true: Boolean, // should the logger catch, log, and re-throw errors?
diff = false: Boolean, // (alpha) show diff between states?
diffPredicate // (alpha) filter function for Latest release
3.0.6 — fixes 3.0.6 2017-05-17Changelog
fix: use Object.assign() instead of object spread operator because non-standard feature 229
fix: removed babel: {} options from package.json
fix: remove dangling comma because non-standard feature 230
fix: remove module and jsnext:main properties from package.json