ngrx-store-logger
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -1,1 +0,46 @@ | ||
export declare const storeLogger: (opts?: Object) => (reducer: Function) => (state: any, action: any) => any; | ||
export declare const storeLogger: (opts?: LoggerOptions) => (reducer: Function) => (state: any, action: any) => any; | ||
export interface LoggerOptions { | ||
/** | ||
* 'log' | 'console' | 'warn' | 'error' | 'info'. Default: 'log' | ||
*/ | ||
level?: any; | ||
/** | ||
* Should log group be collapsed? default: false | ||
*/ | ||
collapsed?: boolean; | ||
/** | ||
* Print duration with action? default: true | ||
*/ | ||
duration?: boolean; | ||
/** | ||
* Print timestamp with action? default: true | ||
*/ | ||
timestamp?: boolean; | ||
filter?: LoggerFilterOption; | ||
/** | ||
* Transform state before print default: state => state | ||
*/ | ||
stateTransformer?: (state: Object) => Object; | ||
/** | ||
* Transform action before print default: actn => actn | ||
*/ | ||
actionTransformer?: (actn: Object) => Object; | ||
colors?: LoggerColorsOption; | ||
} | ||
export interface LoggerFilterOption { | ||
/** | ||
* Only print actions included in this list - has priority over blacklist | ||
*/ | ||
whitelist?: string[]; | ||
/** | ||
* Only print actions that are NOT included in this list | ||
*/ | ||
blacklist?: string[]; | ||
} | ||
export interface LoggerColorsOption { | ||
title: (action: Object) => string; | ||
prevState: (prevState: Object) => string; | ||
action: (action: Object) => string; | ||
nextState: (nextState: Object) => string; | ||
error: (error: any, prevState: Object) => string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var logger = console; | ||
@@ -6,3 +7,3 @@ var INIT_ACTION = "@ngrx/store/init"; | ||
var pad = function (num, maxLength) { return repeat("0", maxLength - num.toString().length) + num; }; | ||
var formatTime = function (time) { return ("@ " + pad(time.getHours(), 2) + ":" + pad(time.getMinutes(), 2) + ":" + pad(time.getSeconds(), 2) + "." + pad(time.getMilliseconds(), 3)); }; | ||
var formatTime = function (time) { return "@ " + pad(time.getHours(), 2) + ":" + pad(time.getMinutes(), 2) + ":" + pad(time.getSeconds(), 2) + "." + pad(time.getMilliseconds(), 3); }; | ||
var timer = typeof performance !== "undefined" && typeof performance.now === "function" ? performance : Date; | ||
@@ -89,2 +90,11 @@ var getLogLevel = function (level, action, payload, type) { | ||
}; }; | ||
var isAllowed = function (action, filter) { | ||
if (!filter) { | ||
return true; | ||
} | ||
if (filter.whitelist && filter.whitelist.length) { | ||
return filter.whitelist.indexOf(action.type) !== -1; | ||
} | ||
return filter.blacklist && filter.blacklist.indexOf(action.type) === -1; | ||
}; | ||
exports.storeLogger = function (opts) { | ||
@@ -102,4 +112,24 @@ if (opts === void 0) { opts = {}; } | ||
} | ||
var colors; | ||
if (ms_ie) { | ||
// Setting colors functions to null when it's an IE browser. | ||
colors = { | ||
title: null, | ||
prevState: null, | ||
action: null, | ||
nextState: null, | ||
error: null, | ||
}; | ||
} | ||
else { | ||
colors = { | ||
title: null, | ||
prevState: function () { return '#9E9E9E'; }, | ||
action: function () { return '#03A9F4'; }, | ||
nextState: function () { return '#4CAF50'; }, | ||
error: function () { return '#F20404'; }, | ||
}; | ||
} | ||
var defaults = { | ||
level: "log", | ||
level: 'log', | ||
collapsed: false, | ||
@@ -110,9 +140,7 @@ duration: true, | ||
actionTransformer: function (actn) { return actn; }, | ||
colors: ms_ie ? {} : { | ||
title: function () { return "#000000"; }, | ||
prevState: function () { return "#9E9E9E"; }, | ||
action: function () { return "#03A9F4"; }, | ||
nextState: function () { return "#4CAF50"; }, | ||
error: function () { return "#F20404"; }, | ||
} | ||
filter: { | ||
whitelist: [], | ||
blacklist: [] | ||
}, | ||
colors: colors | ||
}; | ||
@@ -136,3 +164,3 @@ var options = Object.assign({}, defaults, opts); | ||
//ignore init action fired by store and devtools | ||
if (action.type !== INIT_ACTION) { | ||
if (action.type !== INIT_ACTION && isAllowed(action, options.filter)) { | ||
buffer([log]); | ||
@@ -144,1 +172,3 @@ } | ||
}; | ||
; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "ngrx-store-logger", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Advanced logging middleware for @ngrx/store", | ||
@@ -8,4 +8,3 @@ "main": "./dist/index.js", | ||
"build_dist": "rm -rf dist && tsc", | ||
"prepublish": "npm run typings && npm run build_dist", | ||
"typings": "typings install" | ||
"prepublish": "npm run build_dist" | ||
}, | ||
@@ -31,18 +30,18 @@ "repository": { | ||
"peerDependencies": { | ||
"rxjs": "^5.0.0-beta.6", | ||
"@ngrx/store": "^2.0.1" | ||
"@ngrx/store": "^2.2.1" | ||
}, | ||
"devDependencies": { | ||
"@ngrx/core": "^1.0.1", | ||
"@angular/core": "^2.4.7", | ||
"@ngrx/core": "^1.2.0", | ||
"@ngrx/store": "^2.2.1", | ||
"es6-promise": "^3.0.2", | ||
"es6-shim": "^0.33.13", | ||
"reflect-metadata": "0.1.2", | ||
"es6-shim": "^0.35.0", | ||
"reflect-metadata": "0.1.10", | ||
"rimraf": "^2.5.1", | ||
"tslint": "^3.4.0", | ||
"typescript": "^1.7.3", | ||
"typings": "^0.6.6", | ||
"@ngrx/store": "^2.0.1", | ||
"rxjs": "^5.0.0-beta.6" | ||
"typescript": "^2.1.4", | ||
"rxjs": "^5.4.0", | ||
"zone.js": "^0.7.7" | ||
}, | ||
"typings": "./dist/index.d.ts" | ||
} |
@@ -59,2 +59,6 @@ # ngrx-store-logger | ||
timestamp? : boolean; //Print timestamp with action? default: true | ||
filter?: { | ||
whitelist?: string[], // Only print actions included in this list - has priority over blacklist | ||
blacklist?: string[] // Only print actions that are NOT included in this list | ||
} | ||
stateTransformer? : (state : Object) => Object; //Transform state before print default: state => state | ||
@@ -71,1 +75,30 @@ actionTransformer? : (actn : Object) => Object; //Transform action before print default: actn => actn | ||
``` | ||
### Filtering | ||
#### Whitelist | ||
Only actions included in the list will be printed | ||
Example: | ||
``` ts | ||
const options: LoggerOptions = { | ||
filter: { | ||
whitelist: ['set-value'] | ||
} | ||
} | ||
storeLogger(options) : Reducer | ||
``` | ||
With this setup, only action *set-value* will be logged | ||
#### Blacklist | ||
Action included in the blacklist will not be printed | ||
Example: | ||
``` ts | ||
const options: LoggerOptions = { | ||
filter: { | ||
blacklist: ['set-value'] | ||
} | ||
} | ||
storeLogger(options) : Reducer | ||
``` | ||
With this setup, all actions except *set-value* will be printed | ||
*Note*: Whitelist has predence over blacklist. If both are defined, only whitelist will be considered |
106
src/index.ts
@@ -87,3 +87,13 @@ declare var console; | ||
export const storeLogger = (opts : Object = {}) => (reducer : Function) => { | ||
const isAllowed = (action, filter) => { | ||
if (!filter) { | ||
return true; | ||
} | ||
if (filter.whitelist && filter.whitelist.length) { | ||
return filter.whitelist.indexOf(action.type) !== -1; | ||
} | ||
return filter.blacklist && filter.blacklist.indexOf(action.type) === -1; | ||
}; | ||
export const storeLogger = (opts: LoggerOptions = {}) => (reducer: Function) => { | ||
let log = {}; | ||
@@ -100,16 +110,34 @@ const ua = typeof window !== 'undefined' && window.navigator.userAgent ? window.navigator.userAgent : ''; | ||
const defaults = { | ||
level : `log`, | ||
collapsed : false, | ||
duration : true, | ||
timestamp : true, | ||
stateTransformer : state => state, | ||
actionTransformer : actn => actn, | ||
colors : ms_ie ? {} : { | ||
title: () => `#000000`, | ||
prevState: () => `#9E9E9E`, | ||
action: () => `#03A9F4`, | ||
nextState: () => `#4CAF50`, | ||
error: () => `#F20404`, | ||
let colors: LoggerColorsOption; | ||
if (ms_ie) { | ||
// Setting colors functions to null when it's an IE browser. | ||
colors = { | ||
title: null, | ||
prevState: null, | ||
action: null, | ||
nextState: null, | ||
error: null, | ||
} | ||
} else { | ||
colors = { | ||
title: null, | ||
prevState: () => '#9E9E9E', | ||
action: () => '#03A9F4', | ||
nextState: () => '#4CAF50', | ||
error: () => '#F20404', | ||
} | ||
} | ||
const defaults: LoggerOptions = { | ||
level: 'log', | ||
collapsed: false, | ||
duration: true, | ||
timestamp: true, | ||
stateTransformer: state => state, | ||
actionTransformer: actn => actn, | ||
filter: { | ||
whitelist: [], | ||
blacklist: [] | ||
}, | ||
colors: colors | ||
}; | ||
@@ -137,3 +165,3 @@ | ||
//ignore init action fired by store and devtools | ||
if(action.type !== INIT_ACTION) { | ||
if(action.type !== INIT_ACTION && isAllowed(action, options.filter)) { | ||
buffer([log]); | ||
@@ -145,1 +173,49 @@ } | ||
}; | ||
export interface LoggerOptions { | ||
/** | ||
* 'log' | 'console' | 'warn' | 'error' | 'info'. Default: 'log' | ||
*/ | ||
level?: any; | ||
/** | ||
* Should log group be collapsed? default: false | ||
*/ | ||
collapsed?: boolean; | ||
/** | ||
* Print duration with action? default: true | ||
*/ | ||
duration?: boolean; | ||
/** | ||
* Print timestamp with action? default: true | ||
*/ | ||
timestamp?: boolean; | ||
filter?: LoggerFilterOption; | ||
/** | ||
* Transform state before print default: state => state | ||
*/ | ||
stateTransformer?: (state: Object) => Object; | ||
/** | ||
* Transform action before print default: actn => actn | ||
*/ | ||
actionTransformer?: (actn: Object) => Object; | ||
colors?: LoggerColorsOption; | ||
}; | ||
export interface LoggerFilterOption { | ||
/** | ||
* Only print actions included in this list - has priority over blacklist | ||
*/ | ||
whitelist?: string[]; | ||
/** | ||
* Only print actions that are NOT included in this list | ||
*/ | ||
blacklist?: string[]; | ||
} | ||
export interface LoggerColorsOption { | ||
title: (action: Object) => string; | ||
prevState: (prevState: Object) => string; | ||
action: (action: Object) => string; | ||
nextState: (nextState: Object) => string; | ||
error: (error: any, prevState: Object) => string; | ||
} |
{ | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"declaration": true | ||
}, | ||
"files": [ | ||
"typings/main.d.ts", | ||
"src/index.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"declaration": true, | ||
"lib": ["es2015", "dom"], | ||
"sourceMap": true | ||
}, | ||
"files": [ | ||
"src/index.ts" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29672
1
419
103
11