
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
redux-logger
Advanced tools

npm i --save redux-logger
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).
{
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`
}
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: Stringaction(action: Object) => level: StringnextState(nextState: Object) => level: Stringerror(error: Any, prevState: Object) => level: StringDefault: log
Print duration of each action?
Default: false
Print timestamp with each action?
Default: true
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: StringprevState(prevState: Object) => color: Stringaction(action: Object) => color: StringnextState(nextState: Object) => color: Stringerror(error: Any, prevState: Object) => color: StringImplementation of the console API. Useful if you are using a custom, wrapped version of console.
Default: console
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
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
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)
Transform state before print. Eg. convert Immutable object to plain JSON.
Default: identity function
Transform action before print. Eg. convert Immutable object to plain JSON.
Default: identity function
Transform error before print.
Default: identity function
Format the title used for each action.
Default: prints something like action @ ${time} ${action.type} (in ${took.toFixed(2)} ms)
Show states diff.
Default: false
Filter states diff for certain cases.
Default: undefined
const middlewares = [];
if (process.env.NODE_ENV === `development`) {
const { logger } = require(`redux-logger`);
middlewares.push(logger);
}
const store = compose(applyMiddleware(...middlewares))(createStore)(reducer);
createLogger({
predicate: (getState, action) => action.type !== AUTH_REMOVE_TOKEN
});
createLogger({
collapsed: (getState, action) => action.type === FORM_CHANGE
});
createLogger({
collapsed: (getState, action, logEntry) => !logEntry.error
});
combineReducers)import { Iterable } from 'immutable';
const stateTransformer = (state) => {
if (Iterable.isIterable(state)) return state.toJS();
else return state;
};
const logger = createLogger({
stateTransformer,
});
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;
}
});
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
});
Feel free to create PR for any of those tasks!
MIT
redux-devtools-extension is a package that integrates Redux with the Redux DevTools browser extension. It provides a more visual and interactive way to inspect actions and state changes, including time-travel debugging, which is not available in redux-logger.
redux-immutable-state-invariant is a middleware that logs warnings when the state is mutated. While it doesn't log actions and state changes like redux-logger, it helps catch bugs related to state mutations, which can be a complementary tool for debugging Redux applications.
FAQs
Logger for Redux
The npm package redux-logger receives a total of 626,376 weekly downloads. As such, redux-logger popularity was classified as popular.
We found that redux-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.