redux-logger vs redux-devtools-extension vs redux-devtools
Redux Middleware and Development Tools Comparison
1 Year
redux-loggerredux-devtools-extensionredux-devtoolsSimilar Packages:
What's Redux Middleware and Development Tools?

Redux middleware and development tools enhance the debugging and state management capabilities of applications using Redux. These packages provide developers with tools to monitor, inspect, and log state changes, making it easier to understand application behavior and diagnose issues. They facilitate a more efficient development process by offering insights into the Redux store, allowing for better tracking of actions and state transitions, which is crucial for maintaining complex applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
redux-logger851,2235,752-598 years agoMIT
redux-devtools-extension775,41613,497-2654 years agoMIT
redux-devtools65,71314,135-2024 years agoMIT
Feature Comparison: redux-logger vs redux-devtools-extension vs redux-devtools

Debugging Capabilities

  • redux-logger:

    Redux Logger provides a straightforward logging mechanism that outputs actions and state changes to the console. While it lacks the advanced features of the other two tools, it is effective for quick debugging and understanding the flow of actions in a simpler setup.

  • redux-devtools-extension:

    The Redux DevTools Extension enhances debugging by providing a user-friendly interface directly in the browser. It allows for real-time inspection of actions and state, as well as advanced features like action replay and state snapshots, which are invaluable for diagnosing complex issues in applications.

  • redux-devtools:

    Redux DevTools offers a comprehensive debugging interface that allows developers to inspect every action dispatched to the store and view the resulting state changes. It supports time travel debugging, enabling developers to step back and forth through state changes, making it easier to identify issues and understand application flow.

Integration

  • redux-logger:

    Redux Logger is easy to integrate into any Redux application. It requires minimal configuration and can be added as middleware, making it a quick solution for logging actions without the need for extensive setup.

  • redux-devtools-extension:

    The Redux DevTools Extension is specifically designed for web applications and integrates seamlessly with modern browsers. It requires minimal setup and is ideal for developers who want a quick and efficient way to debug their applications directly in the browser.

  • redux-devtools:

    Redux DevTools can be integrated into any Redux application, regardless of the environment. It can be used with various frameworks and libraries, making it a versatile choice for developers looking for a robust debugging solution.

Performance Impact

  • redux-logger:

    Redux Logger is lightweight and has a minimal performance impact, making it suitable for applications where logging is needed without significant overhead. However, it is recommended to disable it in production environments to avoid unnecessary logging.

  • redux-devtools-extension:

    The Redux DevTools Extension is designed to minimize performance impact during development. It allows developers to selectively enable or disable features, ensuring that performance remains optimal while still providing robust debugging capabilities.

  • redux-devtools:

    While Redux DevTools provides powerful debugging features, it can introduce some performance overhead, especially in large applications with frequent state updates. However, its benefits often outweigh the costs during development, as it aids in identifying performance bottlenecks.

Ease of Use

  • redux-logger:

    Redux Logger is straightforward to set up and use. It requires minimal configuration, making it accessible for developers who want quick logging capabilities without the need for complex setups.

  • redux-devtools-extension:

    The Redux DevTools Extension is exceptionally easy to use, with a clean interface that integrates directly into the browser. Developers can quickly access and utilize its features without extensive documentation, making it a popular choice for web development.

  • redux-devtools:

    Redux DevTools offers a user-friendly interface that is intuitive for developers. Its features are accessible and provide a clear view of the Redux store, making it easy to navigate and understand state changes.

Use Cases

  • redux-logger:

    Redux Logger is perfect for smaller applications or during the early stages of development when quick insights into actions and state changes are needed without the overhead of a full debugging tool.

  • redux-devtools-extension:

    The Redux DevTools Extension is best suited for web applications where developers need real-time insights into state changes and actions. It is particularly beneficial during the development phase to ensure a smooth user experience.

  • redux-devtools:

    Redux DevTools is ideal for developers working on complex applications that require in-depth state management and debugging capabilities. It is particularly useful for applications with intricate state transitions and interactions.

How to Choose: redux-logger vs redux-devtools-extension vs redux-devtools
  • redux-logger:

    Select Redux Logger if you want a simple and effective way to log Redux actions and state changes to the console. It is lightweight and easy to set up, providing clear visibility into the flow of actions and state updates without the overhead of a full debugging tool.

  • redux-devtools-extension:

    Opt for Redux DevTools Extension if you are developing a web application and want a seamless integration with your browser. This extension offers enhanced features such as time travel debugging and state persistence, making it easier to track changes over time and revert to previous states.

  • redux-devtools:

    Choose Redux DevTools if you need a standalone tool for debugging Redux applications. It provides a powerful interface for inspecting actions and state changes, and it can be integrated with various environments, including Chrome and Firefox extensions.

README for redux-logger

Logger for Redux

npm npm Build Status

redux-logger

Table of contents

Install

npm i --save redux-logger

Usage

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:

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

{
  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/evgenyrodionov/redux-logger/blob/master/src/defaults.js#L12-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 showing states diff, similar to `predicate`
}

Options description

level (String | Function | Object)

Level of console. warn, error, info or else.

It can be a function (action: Object) => level: String.

It can be an object with level string for: prevState, action, nextState, error

It can be an object with getter functions: prevState, action, nextState, error. Useful if you want to print message based on specific state or action. Set any of them to false if you want to hide it.

  • prevState(prevState: Object) => level: String
  • action(action: Object) => level: String
  • nextState(nextState: Object) => level: String
  • error(error: Any, prevState: Object) => level: String

Default: log

duration (Boolean)

Print duration of each action?

Default: false

timestamp (Boolean)

Print timestamp with each action?

Default: true

colors (Object)

Object with color getter functions: title, prevState, action, nextState, error. Useful if you want to paint message based on specific state or action. Set any of them to false if you want to show plain message without colors.

  • title(action: Object) => color: String
  • prevState(prevState: Object) => color: String
  • action(action: Object) => color: String
  • nextState(nextState: Object) => color: String
  • error(error: Any, prevState: Object) => color: String

logger (Object)

Implementation of the console API. Useful if you are using a custom, wrapped version of console.

Default: console

logErrors (Boolean)

Should the logger catch, log, and re-throw errors? This makes it clear which action triggered the error but makes "break on error" in dev tools harder to use, as it breaks on re-throw rather than the original throw location.

Default: true

collapsed = (getState: Function, action: Object, logEntry: Object) => Boolean

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.

Default: false

predicate = (getState: Function, action: Object) => Boolean

If specified this function will be called before each action is processed with this middleware. Receives getState function for accessing current store state and action object as parameters. Returns true if action should be logged, false otherwise.

Default: null (always log)

stateTransformer = (state: Object) => state

Transform state before print. Eg. convert Immutable object to plain JSON.

Default: identity function

actionTransformer = (action: Object) => action

Transform action before print. Eg. convert Immutable object to plain JSON.

Default: identity function

errorTransformer = (error: Any) => error

Transform error before print.

Default: identity function

titleFormatter = (action: Object, time: String?, took: Number?) => title

Format the title used for each action.

Default: prints something like action @ ${time} ${action.type} (in ${took.toFixed(2)} ms)

diff (Boolean)

Show states diff.

Default: false

diffPredicate = (getState: Function, action: Object) => Boolean

Filter states diff for certain cases.

Default: undefined

Recipes

Log only in development

const middlewares = [];

if (process.env.NODE_ENV === `development`) {
  const { logger } = require(`redux-logger`);

  middlewares.push(logger);
}

const store = compose(applyMiddleware(...middlewares))(createStore)(reducer);

Log everything except actions with certain type

createLogger({
  predicate: (getState, action) => action.type !== AUTH_REMOVE_TOKEN
});

Collapse actions with certain type

createLogger({
  collapsed: (getState, action) => action.type === FORM_CHANGE
});

Collapse actions that don't have errors

createLogger({
  collapsed: (getState, action, logEntry) => !logEntry.error
});

Transform Immutable (without combineReducers)

import { Iterable } from 'immutable';

const stateTransformer = (state) => {
  if (Iterable.isIterable(state)) return state.toJS();
  else return state;
};

const logger = createLogger({
  stateTransformer,
});

Transform Immutable (with combineReducers)

const logger = createLogger({
  stateTransformer: (state) => {
    let newState = {};

    for (var i of Object.keys(state)) {
      if (Immutable.Iterable.isIterable(state[i])) {
        newState[i] = state[i].toJS();
      } else {
        newState[i] = state[i];
      }
    };

    return newState;
  }
});

Log batched actions

Thanks to @smashercosmo

import { createLogger } from 'redux-logger';

const actionTransformer = action => {
  if (action.type === 'BATCHING_REDUCER.BATCH') {
    action.payload.type = action.payload.map(next => next.type).join(' => ');
    return action.payload;
  }

  return action;
};

const level = 'info';

const logger = {};

for (const method in console) {
  if (typeof console[method] === 'function') {
    logger[method] = console[method].bind(console);
  }
}

logger[level] = function levelFn(...args) {
  const lastArg = args.pop();

  if (Array.isArray(lastArg)) {
    return lastArg.forEach(item => {
      console[level].apply(console, [...args, item]);
    });
  }

  console[level].apply(console, arguments);
};

export default createLogger({
  level,
  actionTransformer,
  logger
});

To Do

  • [x] Update eslint config to airbnb's
  • [ ] Clean up code, because it's very messy, to be honest
  • [ ] Write tests
  • [ ] Node.js support
  • [ ] React-native support

Feel free to create PR for any of those tasks!

Known issues

  • Performance issues in react-native (#32)

License

MIT