redux-logger vs axios-debug-log vs react-native-logs vs react-native-network-logger
Logging and Debugging in JavaScript Applications Comparison
1 Year
redux-loggeraxios-debug-logreact-native-logsreact-native-network-logger
What's Logging and Debugging in JavaScript Applications?

Logging and debugging libraries in JavaScript provide developers with tools to track application behavior, identify issues, and analyze performance. These libraries enhance the built-in console logging capabilities by offering features like structured logging, log levels, remote logging, and integration with external services. They help improve code quality, facilitate troubleshooting, and provide insights into application performance, making them essential for both development and production environments. axios-debug-log is a lightweight library that enhances Axios HTTP requests with detailed logging capabilities, making it easier to debug network interactions. react-native-logs is a versatile logging library designed for React Native applications, offering features like log levels, remote logging, and customizable log formats. react-native-network-logger is a specialized tool for logging network requests and responses in React Native apps, providing insights into API interactions and helping developers diagnose network-related issues. redux-logger is a middleware for Redux that logs actions and state changes in a Redux store, making it invaluable for debugging state management in React applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
redux-logger1,004,5205,749-588 years agoMIT
axios-debug-log67,6501337.79 kB2-BSD-3-Clause
react-native-logs45,781525168 kB118 months agoMIT
react-native-network-logger40,805608396 kB139 months agoMIT
Feature Comparison: redux-logger vs axios-debug-log vs react-native-logs vs react-native-network-logger

Logging Capabilities

  • redux-logger:

    redux-logger logs Redux actions and state changes, including the previous state, action, and next state. It provides a clear, time-traveling view of how actions affect the Redux store, making it easier to debug state management.

  • axios-debug-log:

    axios-debug-log provides detailed logging of Axios requests and responses, including headers, payloads, and timing information. It helps developers understand the flow of data between the client and server, making it easier to identify issues.

  • react-native-logs:

    react-native-logs offers flexible logging with support for multiple log levels (e.g., debug, info, warn, error), remote logging, and customizable log formats. It allows developers to log messages with varying levels of importance, making it easier to filter and analyze logs.

  • react-native-network-logger:

    react-native-network-logger focuses on logging network requests and responses, including URL, method, status code, and response time. It provides a clear overview of API interactions, helping developers diagnose network-related problems.

Integration

  • redux-logger:

    redux-logger is middleware that can be easily added to a Redux store. It requires minimal configuration and works out of the box with any Redux setup.

  • axios-debug-log:

    axios-debug-log integrates seamlessly with Axios, requiring minimal setup. It can be configured globally or on a per-request basis, allowing for flexible logging without disrupting existing code.

  • react-native-logs:

    react-native-logs can be integrated into React Native applications with a simple setup. It supports both local and remote logging, making it versatile for different environments.

  • react-native-network-logger:

    react-native-network-logger is easy to integrate into React Native apps, requiring only a few lines of code to start logging network requests and responses.

Customization

  • redux-logger:

    redux-logger allows for some customization of log output, including the ability to modify how actions and state are displayed. However, it is primarily designed to log Redux actions and state changes as-is.

  • axios-debug-log:

    axios-debug-log allows for some customization of log messages, including the ability to format logs and filter which requests/responses are logged. However, it is primarily focused on logging Axios interactions.

  • react-native-logs:

    react-native-logs offers extensive customization options, including the ability to define custom log levels, formats, and remote logging endpoints. This makes it highly adaptable to different logging needs.

  • react-native-network-logger:

    react-native-network-logger provides limited customization, focusing mainly on the format of network logs. It is designed to be straightforward and easy to use without extensive configuration.

Use Case

  • redux-logger:

    Use redux-logger when you want to debug state changes in applications that use Redux for state management. It is particularly useful for tracking how actions affect the state and identifying issues with the Redux flow.

  • axios-debug-log:

    Use axios-debug-log when you need to debug HTTP requests and responses in applications that use Axios for API calls. It is particularly useful for identifying issues with network interactions, such as incorrect payloads or unexpected responses.

  • react-native-logs:

    Use react-native-logs for general-purpose logging in React Native applications. It is suitable for logging errors, warnings, and informational messages throughout the app, making it easier to monitor and troubleshoot issues.

  • react-native-network-logger:

    Use react-native-network-logger when you want to gain insights into network activity in your React Native app. It is helpful for diagnosing problems with API calls, such as slow responses or failed requests.

Ease of Use: Code Examples

  • redux-logger:

    redux-logger Example

    import { createStore, applyMiddleware } from 'redux';
    import { createLogger } from 'redux-logger';
    import rootReducer from './reducers';
    
    // Create a logger middleware
    const logger = createLogger();
    
    // Create a Redux store with logger middleware
    const store = createStore(rootReducer, applyMiddleware(logger));
    
    // Dispatch an action (example)
    store.dispatch({ type: 'EXAMPLE_ACTION', payload: 'data' });
    
  • axios-debug-log:

    axios-debug-log Example

    import axios from 'axios';
    import { enableLogging } from 'axios-debug-log';
    
    // Enable logging for Axios requests and responses
    enableLogging({
      request: (debug, config) => {
        debug('Request with ', config);
      },
      response: (debug, response) => {
        debug('Response with ', response);
      },
    });
    
    // Make an Axios request
    axios.get('https://api.example.com/data');
    
  • react-native-logs:

    react-native-logs Example

    import { Log } from 'react-native-logs';
    
    // Create a logger instance
    const logger = Log.createLogger({
      severity: 'debug',
      transport: Log.transports.Console,
    });
    
    // Log messages with different levels
    logger.debug('This is a debug message');
    logger.info('This is an info message');
    logger.warn('This is a warning message');
    logger.error('This is an error message');
    
  • react-native-network-logger:

    react-native-network-logger Example

    import { NetworkLogger } from 'react-native-network-logger';
    
    // Start logging network requests
    NetworkLogger.start();
    
    // Make a network request (example)
    fetch('https://api.example.com/data').then(response => response.json());
    
How to Choose: redux-logger vs axios-debug-log vs react-native-logs vs react-native-network-logger
  • redux-logger:

    Choose redux-logger if you are using Redux for state management and need to log actions and state changes for debugging purposes. It provides clear insights into the Redux flow.

  • axios-debug-log:

    Choose axios-debug-log if you need to enhance Axios requests with detailed logging for debugging network interactions. It is lightweight and easy to integrate into existing Axios setups.

  • react-native-logs:

    Choose react-native-logs if you need a comprehensive logging solution for React Native applications with support for multiple log levels, remote logging, and customizable formats.

  • react-native-network-logger:

    Choose react-native-network-logger if you want a focused tool for logging network requests and responses in React Native apps. It is useful for diagnosing API interactions and network issues.

README for redux-logger

Logger for Redux

npm npm Build Status

redux-logger

Table of contents

Install

npm i --save redux-logger

Usage

import { applyMiddleware, createStore } from 'redux';

// Logger with default options
import logger from 'redux-logger'
const store = createStore(
  reducer,
  applyMiddleware(logger)
)

// Note passing middleware as the third argument requires redux@>=3.1.0

Or you can create your own logger with custom options:

import { applyMiddleware, createStore } from 'redux';
import { createLogger } from 'redux-logger'

const logger = createLogger({
  // ...options
});

const store = createStore(
  reducer,
  applyMiddleware(logger)
);

Note: logger must be the last middleware in chain, otherwise it will log thunk and promise, not actual actions (#20).

Options

{
  predicate, // if specified this function will be called before each action is processed with this middleware.
  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.
  duration = false: Boolean, // print the duration of each action?
  timestamp = true: Boolean, // print the timestamp with each action?

  level = 'log': 'log' | 'console' | 'warn' | 'error' | 'info', // console's level
  colors: ColorsObject, // colors for title, prev state, action and next state: https://github.com/evgenyrodionov/redux-logger/blob/master/src/defaults.js#L12-L18
  titleFormatter, // Format the title used when logging actions.

  stateTransformer, // Transform state before print. Eg. convert Immutable object to plain JSON.
  actionTransformer, // Transform action before print. Eg. convert Immutable object to plain JSON.
  errorTransformer, // Transform error before print. Eg. convert Immutable object to plain JSON.

  logger = console: LoggerObject, // implementation of the `console` API.
  logErrors = true: Boolean, // should the logger catch, log, and re-throw errors?

  diff = false: Boolean, // (alpha) show diff between states?
  diffPredicate // (alpha) filter function for showing states diff, similar to `predicate`
}

Options description

level (String | Function | Object)

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

duration (Boolean)

Print duration of each action?

Default: false

timestamp (Boolean)

Print timestamp with each action?

Default: true

colors (Object)

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

logger (Object)

Implementation of the console API. Useful if you are using a custom, wrapped version of console.

Default: console

logErrors (Boolean)

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

collapsed = (getState: Function, action: Object, logEntry: Object) => Boolean

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

predicate = (getState: Function, action: Object) => Boolean

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)

stateTransformer = (state: Object) => state

Transform state before print. Eg. convert Immutable object to plain JSON.

Default: identity function

actionTransformer = (action: Object) => action

Transform action before print. Eg. convert Immutable object to plain JSON.

Default: identity function

errorTransformer = (error: Any) => error

Transform error before print.

Default: identity function

titleFormatter = (action: Object, time: String?, took: Number?) => title

Format the title used for each action.

Default: prints something like action @ ${time} ${action.type} (in ${took.toFixed(2)} ms)

diff (Boolean)

Show states diff.

Default: false

diffPredicate = (getState: Function, action: Object) => Boolean

Filter states diff for certain cases.

Default: undefined

Recipes

Log only in development

const middlewares = [];

if (process.env.NODE_ENV === `development`) {
  const { logger } = require(`redux-logger`);

  middlewares.push(logger);
}

const store = compose(applyMiddleware(...middlewares))(createStore)(reducer);

Log everything except actions with certain type

createLogger({
  predicate: (getState, action) => action.type !== AUTH_REMOVE_TOKEN
});

Collapse actions with certain type

createLogger({
  collapsed: (getState, action) => action.type === FORM_CHANGE
});

Collapse actions that don't have errors

createLogger({
  collapsed: (getState, action, logEntry) => !logEntry.error
});

Transform Immutable (without combineReducers)

import { Iterable } from 'immutable';

const stateTransformer = (state) => {
  if (Iterable.isIterable(state)) return state.toJS();
  else return state;
};

const logger = createLogger({
  stateTransformer,
});

Transform Immutable (with combineReducers)

const logger = 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;
  }
});

Log batched actions

Thanks to @smashercosmo

import { createLogger } from 'redux-logger';

const actionTransformer = action => {
  if (action.type === 'BATCHING_REDUCER.BATCH') {
    action.payload.type = action.payload.map(next => next.type).join(' => ');
    return action.payload;
  }

  return action;
};

const level = 'info';

const logger = {};

for (const method in console) {
  if (typeof console[method] === 'function') {
    logger[method] = console[method].bind(console);
  }
}

logger[level] = function levelFn(...args) {
  const lastArg = args.pop();

  if (Array.isArray(lastArg)) {
    return lastArg.forEach(item => {
      console[level].apply(console, [...args, item]);
    });
  }

  console[level].apply(console, arguments);
};

export default createLogger({
  level,
  actionTransformer,
  logger
});

To Do

  • [x] Update eslint config to airbnb's
  • [ ] Clean up code, because it's very messy, to be honest
  • [ ] Write tests
  • [ ] Node.js support
  • [ ] React-native support

Feel free to create PR for any of those tasks!

Known issues

  • Performance issues in react-native (#32)

License

MIT