Giter VIP home page Giter VIP logo

redux-cli-logger's Introduction

redux-cli-logger

A redux logger for command-line environments (node.js)

No innovations here, just a logger middleware for redux that will write all redux actions and state changes to the node.js console.

Configuration and output format inspired by redux-logger

redux-node-logger screenshot

Installation

npm install --save-dev redux-cli-logger

Usage

redux-cli-logger must be called as a function before being utilized as middleware. This allows passing in options to overwrite all colors and arrow icons, as well as a predicate that functions like that in redux-logger. Here's what a simple configureStore function might look like:

import reducer from '../reducers'
import createCLILogger from 'redux-cli-logger'

const middleware = [
  // your middleware here
]

if (process.env.NODE_ENV === 'development') {
  const loggerOptions = {
    predicate: (getState, action) => !action.MONITOR_ACTION
  }
  const logger = createCLILogger(loggerOptions)
  middleware.push(logger)
}

const enhancer = compose(
  applyMiddleware(...middleware)
  // optionally, electron-enhancer, redux-loop, etc.
)

const initialState = {}
const store = createStore(reducer, initialState, enhancer)

Configuration

The options object has overridable defaults that look like this:

{
  downArrow: '▼',
  rightArrow: '▶',
  messageColor: 'bright-yellow',
  prevColor: 'grey',
  actionColor: 'bright-blue',
  nextColor: 'green',
  // when non-null, only prints if predicate(getState, action) is truthy
  predicate: null,
  // useful to trim parts of the state atom that are too verbose
  stateTransformer: (state) => state,
  // useful to censor private messages (containing password, etc.)
  actionTransformer: (action) => action,
}

redux-cli-logger's People

Contributors

fasterthanlime avatar low-ghost avatar

Watchers

James Cloos avatar Justin Echternach avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.