Skip to content

Instantly share code, notes, and snippets.

@timbuckley
Created March 24, 2016 17:02
Show Gist options
  • Save timbuckley/7099f8b7543960eff6e7 to your computer and use it in GitHub Desktop.
Save timbuckley/7099f8b7543960eff6e7 to your computer and use it in GitHub Desktop.
Super simple logging middleware for Redux
import Conf from '../conf' // Various app-level options, including a logging flag.
const logger = store => next => action => {
// Middleware format.
// - Logs each action as they come in,
// - Dispatches the action, and
// - Logs the new state.
if (Conf.logging && typeof console.group === 'function') {
console.group(action.type)
console.info('📲 dispatching', action)
let result = next(action)
console.log('💽 next state', store.getState())
console.groupEnd(action.type)
return result
}
return next(action)
}
export default logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment