![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
redux-logger
Advanced tools
redux-logger is a middleware for Redux that logs actions and state changes to the console, making it easier to debug and understand the flow of data in your application.
Basic Logging
This feature logs every action and the resulting new state to the console. It helps developers see what actions are being dispatched and how the state is changing in response.
const { createStore, applyMiddleware } = require('redux');
const logger = require('redux-logger').createLogger();
const reducer = (state = {}, action) => state;
const store = createStore(reducer, applyMiddleware(logger));
store.dispatch({ type: 'TEST_ACTION' });
Collapsed Logging
This feature collapses the log entries for each action, making the console output more compact and easier to navigate, especially when dealing with a large number of actions.
const { createStore, applyMiddleware } = require('redux');
const { createLogger } = require('redux-logger');
const logger = createLogger({ collapsed: true });
const reducer = (state = {}, action) => state;
const store = createStore(reducer, applyMiddleware(logger));
store.dispatch({ type: 'TEST_ACTION' });
Predicate Logging
This feature allows you to filter which actions get logged based on a predicate function. In this example, actions of type 'IGNORED_ACTION' will not be logged.
const { createStore, applyMiddleware } = require('redux');
const { createLogger } = require('redux-logger');
const logger = createLogger({ predicate: (getState, action) => action.type !== 'IGNORED_ACTION' });
const reducer = (state = {}, action) => state;
const store = createStore(reducer, applyMiddleware(logger));
store.dispatch({ type: 'TEST_ACTION' });
store.dispatch({ type: 'IGNORED_ACTION' });
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.
npm i --save redux-logger
import createLogger from 'redux-logger';
const logger = createLogger();
const createStoreWithMiddleware = applyMiddleware(logger)(createStore);
const store = createStoreWithMiddleware(reducer);
redux-logger
exposes single constructor function for creating logger middleware.
createLogger(options?: Object)
Level of console
. warn
, error
, info
or else.
Implementation of the console
API. Useful if you are using a custom, wrapped version of console
.
Is group collapsed?
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.
const __DEV__ = true;
createLogger({
predicate: (getState, action) => __DEV__
});
AUTH_REMOVE_TOKEN
createLogger({
predicate: (getState, action) => action.type !== AUTH_REMOVE_TOKEN
});
MIT
FAQs
Logger for Redux
The npm package redux-logger receives a total of 753,332 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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.