Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/react-intl] merge better logger from feature/redux #735

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions src/store/configureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducers';
import createHelpers from './createHelpers';
import createLogger from './logger';

export default function configureStore(initialState, helpersConfig) {
const helpers = createHelpers(helpersConfig);
Expand All @@ -10,19 +11,7 @@ export default function configureStore(initialState, helpersConfig) {
let enhancer;

if (__DEV__) {
if (process.env.BROWSER) {
const createLogger = require('redux-logger'); // eslint-disable-line global-require
middleware.push(createLogger({
collapsed: true,
}));
} else {
// Server side redux action logger
middleware.push(store => next => action => { // eslint-disable-line no-unused-vars
const payload = JSON.stringify(action.payload);
console.log(` * ${action.type}: ${payload}`); // eslint-disable-line no-console
return next(action);
});
}
middleware.push(createLogger());

// https://github.com/zalmoxisus/redux-devtools-extension#redux-devtools-extension
let devToolsExtension = f => f;
Expand Down
7 changes: 7 additions & 0 deletions src/store/logger/logger.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reduxLogger from 'redux-logger';

export default function createLogger() {
return reduxLogger({
collapsed: true,
});
}
12 changes: 12 additions & 0 deletions src/store/logger/logger.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { inspect } from 'util';

// Server side redux action logger
export default function createLogger() {
return store => next => action => { // eslint-disable-line no-unused-vars
const formattedPayload = inspect(action.payload, {
colors: true,
});
console.log(` * ${action.type}: ${formattedPayload}`); // eslint-disable-line no-console
return next(action);
};
}
6 changes: 6 additions & 0 deletions src/store/logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"name": "redux-logger-middleware",
"main": "./logger.server.js",
"browser": "./logger.client.js"
}