Skip to content

Commit

Permalink
feat: implicitly convert action.type to string
Browse files Browse the repository at this point in the history
  • Loading branch information
imevro committed Feb 2, 2017
1 parent 904329c commit 16d588e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* [API](#api)
* [Recipes](#recipes)
* [Log only in development](#log-only-in-development)
* [Transform `Symbol()` action type to string](#transform-symbol-action-type-to-string)
* [Log everything except actions with certain type](#log-everything-except-actions-with-certain-type)
* [Collapse actions with certain type](#collapse-actions-with-certain-type)
* [Transform Immutable (without `combineReducers`)](#transform-immutable-without-combinereducers)
Expand Down Expand Up @@ -176,18 +175,6 @@ if (process.env.NODE_ENV === `development`) {
const store = compose(applyMiddleware(...middlewares))(createStore)(reducer);
```

### Transform `Symbol()` action type to string
```javascript
import createLogger from 'redux-logger';

const logger = createLogger({
actionTransformer: (action) => ({
...action,
type: String(action.type),
})
});
```

### Log everything except actions with certain type
```javascript
createLogger({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-logger",
"version": "2.8.0",
"version": "2.8.1",
"description": "Logger for Redux",
"main": "lib/index.js",
"scripts": {
Expand Down
20 changes: 11 additions & 9 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ function getLogLevel(level, action, payload, type) {

function defaultTitleFormatter(options) {
const {
timestamp, duration,
timestamp,
duration,
} = options;

return (action, time, took) => {
const parts = [`action`];
if (timestamp) {
parts.push(`@ ${time}`);
}
parts.push(action.type);
if (duration) {
parts.push(`(in ${took.toFixed(2)} ms)`);
}

if (timestamp) parts.push(`@ ${time}`);
parts.push(String(action.type));
if (duration) parts.push(`(in ${took.toFixed(2)} ms)`);

return parts.join(` `);
};
}
Expand All @@ -45,7 +44,10 @@ export function printBuffer(buffer, options) {
logger,
actionTransformer,
titleFormatter = defaultTitleFormatter(options),
collapsed, colors, level, diff,
collapsed,
colors,
level,
diff,
} = options;

buffer.forEach((logEntry, key) => {
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ function createLogger(options = {}) {

const {
logger,
transformer, stateTransformer, errorTransformer,
predicate, logErrors,
transformer,
stateTransformer,
errorTransformer,
predicate,
logErrors,
diffPredicate,
} = loggerOptions;

Expand Down

0 comments on commit 16d588e

Please sign in to comment.