Gathering detailed insights and metrics for redux-logger
Gathering detailed insights and metrics for redux-logger
Gathering detailed insights and metrics for redux-logger
Gathering detailed insights and metrics for redux-logger
npm install redux-logger
3.0.6 — fixes
Published on 17 May 2017
[BROKEN] 3.0.2 — chore: webpack → rollup
Published on 17 May 2017
3.0.1 — fixed bug with custom titleFormatter
Published on 30 Mar 2017
3.0.0 — breaking change with exports
Published on 23 Mar 2017
2.10.2 — fixed require()
Published on 21 Mar 2017
2.10.0 — improved readability
Published on 21 Mar 2017
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5,760 Stars
294 Commits
320 Forks
61 Watching
2 Branches
49 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.6%
163,760
Compared to previous day
Last week
2.2%
875,953
Compared to previous week
Last month
14.3%
3,640,054
Compared to previous month
Last year
-1.3%
41,628,061
Compared to previous year
1
23
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.
npm i --save redux-logger
Typescript types are also available, via DefinitelyTyped:
npm i @types/redux-logger
1import { applyMiddleware, createStore } from 'redux'; 2 3// Logger with default options 4import logger from 'redux-logger' 5const store = createStore( 6 reducer, 7 applyMiddleware(logger) 8) 9 10// Note passing middleware as the third argument requires redux@>=3.1.0
Or you can create your own logger with custom options:
1import { applyMiddleware, createStore } from 'redux'; 2import { createLogger } from 'redux-logger' 3 4const logger = createLogger({ 5 // ...options 6}); 7 8const store = createStore( 9 reducer, 10 applyMiddleware(logger) 11);
Note: logger must be the last middleware in chain, otherwise it will log thunk and promise, not actual actions (#20).
1{ 2 predicate, // if specified this function will be called before each action is processed with this middleware. 3 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. 4 duration = false: Boolean, // print the duration of each action? 5 timestamp = true: Boolean, // print the timestamp with each action? 6 7 level = 'log': 'log' | 'console' | 'warn' | 'error' | 'info', // console's level 8 colors: ColorsObject, // colors for title, prev state, action and next state: https://github.com/LogRocket/redux-logger/blob/master/src/defaults.js#L12-L18 9 titleFormatter, // Format the title used when logging actions. 10 11 stateTransformer, // Transform state before print. Eg. convert Immutable object to plain JSON. 12 actionTransformer, // Transform action before print. Eg. convert Immutable object to plain JSON. 13 errorTransformer, // Transform error before print. Eg. convert Immutable object to plain JSON. 14 15 logger = console: LoggerObject, // implementation of the `console` API. 16 logErrors = true: Boolean, // should the logger catch, log, and re-throw errors? 17 18 diff = false: Boolean, // (alpha) show diff between states? 19 diffPredicate // (alpha) filter function for showing states diff, similar to `predicate` 20}
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
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: String
prevState(prevState: Object) => color: String
action(action: Object) => color: String
nextState(nextState: Object) => color: String
error(error: Any, prevState: Object) => color: String
Implementation 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
1const middlewares = []; 2 3if (process.env.NODE_ENV === `development`) { 4 const { logger } = require(`redux-logger`); 5 6 middlewares.push(logger); 7} 8 9const store = compose(applyMiddleware(...middlewares))(createStore)(reducer);
1createLogger({ 2 predicate: (getState, action) => action.type !== AUTH_REMOVE_TOKEN 3});
1createLogger({ 2 collapsed: (getState, action) => action.type === FORM_CHANGE 3});
1createLogger({ 2 collapsed: (getState, action, logEntry) => !logEntry.error 3});
combineReducers
)1import { Iterable } from 'immutable'; 2 3const stateTransformer = (state) => { 4 if (Iterable.isIterable(state)) return state.toJS(); 5 else return state; 6}; 7 8const logger = createLogger({ 9 stateTransformer, 10});
combineReducers
)1const logger = createLogger({ 2 stateTransformer: (state) => { 3 let newState = {}; 4 5 for (var i of Object.keys(state)) { 6 if (Immutable.Iterable.isIterable(state[i])) { 7 newState[i] = state[i].toJS(); 8 } else { 9 newState[i] = state[i]; 10 } 11 }; 12 13 return newState; 14 } 15});
Thanks to @smashercosmo
1import { createLogger } from 'redux-logger'; 2 3const actionTransformer = action => { 4 if (action.type === 'BATCHING_REDUCER.BATCH') { 5 action.payload.type = action.payload.map(next => next.type).join(' => '); 6 return action.payload; 7 } 8 9 return action; 10}; 11 12const level = 'info'; 13 14const logger = {}; 15 16for (const method in console) { 17 if (typeof console[method] === 'function') { 18 logger[method] = console[method].bind(console); 19 } 20} 21 22logger[level] = function levelFn(...args) { 23 const lastArg = args.pop(); 24 25 if (Array.isArray(lastArg)) { 26 return lastArg.forEach(item => { 27 console[level].apply(console, [...args, item]); 28 }); 29 } 30 31 console[level].apply(console, arguments); 32}; 33 34export default createLogger({ 35 level, 36 actionTransformer, 37 logger 38});
Feel free to create PR for any of those tasks!
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/25 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
67 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More