![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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 { applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import promise from 'redux-promise';
import createLogger from 'redux-logger';
const logger = createLogger();
const createStoreWithMiddleware = applyMiddleware(thunk, promise, logger)(createStore);
const store = createStoreWithMiddleware(reducer);
Logger must be last middleware in chain, otherwise it will log thunk and promise, not actual actions (#20).
redux-logger
exposes single constructor function for creating logger middleware.
createLogger(options?: Object)
Level of console
. warn
, error
, info
or else.
Default: log
Print duration of each action?
Default: false
Print timestamp with each action?
Default: true
Object with 3 functions: prevState
, action
, nextState
. Useful if you want paint message based on specific state or action. It also can be false
if you want show plain message without colors.
prevState(prevState: Object) => color: String
action(action: Object) => color: String
nextState(nextState: Object) => color: String
Implementation of the console
API. Useful if you are using a custom, wrapped version of console
.
Default: window.console
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
createLogger({
predicate: (getState, action) => process.env.NODE_ENV === `development`
});
AUTH_REMOVE_TOKEN
createLogger({
predicate: (getState, action) => action.type !== AUTH_REMOVE_TOKEN
});
createLogger({
collapsed: true
});
FORM_CHANGE
createLogger({
collapsed: (getState, action) => action.type === FORM_CHANGE
});
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;
}
});
MIT
FAQs
Logger for Redux
The npm package redux-logger receives a total of 447,364 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.