FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

improve debug output by adding verbose option · feenst/json-rules-engine@266cf37 · GitHub

Commit 266cf37

Browse files
Cache Hamm
committed
improve debug output by adding verbose option
1 parent 2f5616d commit 266cf37

6 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎dist/almanac.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
1919
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2020

2121
var debug = require('debug')('json-rules-engine');
22+
var verbose = require('debug')('json-rules-engine-verbose');
2223

2324
/**
2425
* Fact results lookup
@@ -109,12 +110,12 @@ var Almanac = function () {
109110
}
110111

111112
cacheVal.then(function (val) {
112-
return debug('almanac::factValue cache hit for fact:' + factId + ' cacheKey:' + cacheKey + ' value: ' + JSON.stringify(val) + '<' + (typeof val === 'undefined' ? 'undefined' : _typeof(val)) + '>');
113+
return debug('almanac::factValue cache hit for fact:' + factId + ' value: ' + JSON.stringify(val) + '<' + (typeof val === 'undefined' ? 'undefined' : _typeof(val)) + '>');
113114
});
114115
return _context.abrupt('return', cacheVal);
115116

116117
case 6:
117-
debug('almanac::factValue cache miss for fact:' + factId + ' using cacheKey:' + cacheKey + '; calculating');
118+
verbose('almanac::factValue cache miss for fact:' + factId + '; calculating');
118119
return _context.abrupt('return', this._setFactValue(fact, params, fact.calculate(params, this)));
119120

120121
case 8:

‎dist/engine.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ var Engine = function (_EventEmitter) {
238238
while (1) {
239239
switch (_context2.prev = _context2.next) {
240240
case 0:
241+
debug('engine::run started');
241242
debug('engine::run runtimeFacts:', runtimeFacts);
242243
this.status = RUNNING;
243244
almanac = new _almanac2.default(this.facts, runtimeFacts);
@@ -255,11 +256,12 @@ var Engine = function (_EventEmitter) {
255256
});
256257
cursor.then(function () {
257258
_this4.status = FINISHED;
259+
debug('engine::run completed');
258260
resolve();
259261
}).catch(reject);
260262
}));
261263

262-
case 6:
264+
case 7:
263265
case 'end':
264266
return _context2.stop();
265267
}

‎dist/fact.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1515
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1616

1717
var debug = require('debug')('json-rules-engine');
18+
var verbose = require('debug')('json-rules-engine-verbose');
1819

1920
var Fact = function () {
2021
/**
@@ -109,7 +110,7 @@ var Fact = function () {
109110
}], [{
110111
key: 'hashFromObject',
111112
value: function hashFromObject(obj) {
112-
debug('fact::hashFromObject generating cache key from:', obj);
113+
verbose('fact::hashFromObject generating cache key from:', obj);
113114
return (0, _objectHash2.default)(obj);
114115
}
115116
}]);

‎src/almanac.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
let debug = require('debug')('json-rules-engine')
4+
let verbose = require('debug')('json-rules-engine-verbose')
45

56
import Fact from './fact'
67

@@ -63,10 +64,10 @@ export default class Almanac {
6364
let cacheKey = fact.getCacheKey(params)
6465
let cacheVal = cacheKey && this.factResultsCache.get(cacheKey)
6566
if (cacheVal) {
66-
cacheVal.then(val => debug(`almanac::factValue cache hit for fact:${factId} cacheKey:${cacheKey} value: ${JSON.stringify(val)}<${typeof val}>`))
67+
cacheVal.then(val => debug(`almanac::factValue cache hit for fact:${factId} value: ${JSON.stringify(val)}<${typeof val}>`))
6768
return cacheVal
6869
}
69-
debug(`almanac::factValue cache miss for fact:${factId} using cacheKey:${cacheKey}; calculating`)
70+
verbose(`almanac::factValue cache miss for fact:${factId}; calculating`)
7071
return this._setFactValue(fact, params, fact.calculate(params, this))
7172
}
7273
}

‎src/engine.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class Engine extends EventEmitter {
140140
* @return {Promise} resolves when the engine has completed running
141141
*/
142142
async run (runtimeFacts = new Map()) {
143+
debug(`engine::run started`)
143144
debug(`engine::run runtimeFacts:`, runtimeFacts)
144145
this.status = RUNNING
145146
let almanac = new Almanac(this.facts, runtimeFacts)
@@ -156,6 +157,7 @@ class Engine extends EventEmitter {
156157
})
157158
cursor.then(() => {
158159
this.status = FINISHED
160+
debug(`engine::run completed`)
159161
resolve()
160162
}).catch(reject)
161163
})

‎src/fact.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hash from 'object-hash'
44

55
let debug = require('debug')('json-rules-engine')
6+
let verbose = require('debug')('json-rules-engine-verbose')
67

78
class Fact {
89
/**
@@ -56,7 +57,7 @@ class Fact {
5657
* @return {string} MD5 string based on the hash'd object
5758
*/
5859
static hashFromObject (obj) {
59-
debug(`fact::hashFromObject generating cache key from:`, obj)
60+
verbose(`fact::hashFromObject generating cache key from:`, obj)
6061
return hash(obj)
6162
}
6263

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL