log.js (977B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 /** 7 * A middleware that logs all actions coming through the system 8 * to the console. 9 */ 10 function log() { 11 return next => action => { 12 try { 13 // Only print the action type, rather than printing the whole object 14 console.log("[DISPATCH] action type:", action.type); 15 /* 16 * USE WITH CAUTION!! This will output everything from an action object, 17 * and these can be quite large. Printing out large objects will slow 18 * down tests and cause test failures 19 * 20 * console.log("[DISPATCH]", JSON.stringify(action, null, 2)); 21 */ 22 } catch (e) { 23 // this occurs if JSON.stringify throws. 24 console.warn(e); 25 console.log("[DISPATCH]", action); 26 } 27 next(action); 28 }; 29 } 30 31 exports.log = log;