debug-fabulous 0.1.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/package.json +9 -8
- package/src/lazy-eval.js +10 -14
- package/src/spawn.js +8 -10
- package/yarn-error.log +1056 -0
- package/yarn.lock +984 -0
package/README.md
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
# debug-fabulous [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url]
|
|
2
2
|
|
|
3
3
|
## Install
|
|
4
|
+
|
|
4
5
|
`npm install --save debug-fabulous`
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
## Purpose:
|
|
7
8
|
|
|
8
9
|
Wrapper / Extension around [visionmedia's debug](https://github.com/visionmedia/debug) to allow lazy evaluation of debugging via closure handling.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
## Why would I consider using this library?
|
|
12
|
+
|
|
13
|
+
The main utilities added to this library is lazy log level evaluation. This allows whatever logged strings to only be created and evaluated if a log level is active. This can considerably reduce the amount of memory used in logging when you are not using.
|
|
14
|
+
|
|
15
|
+
With this in mind, there are no excuses to not log anything and everything as performance can be kept in check easily (via log levels).
|
|
16
|
+
|
|
17
|
+
### Proof
|
|
18
|
+
|
|
19
|
+
For analysis of the performance results are in [perfWith.out](./test/perf/perfWith.out) and [perfWithout.out](./test/perf/perfWithout.out).
|
|
20
|
+
|
|
21
|
+
In summary, the tests using this library are using 3 times less memory for the same logging statements (when the log levels are disabled).
|
|
22
|
+
|
|
23
|
+
## This library essentially wraps two things:
|
|
11
24
|
|
|
12
25
|
- [lazy-eval](./src/lazy-eval.js): debug closure handling
|
|
13
26
|
- [spawn](./src/spawn.js): spawns off existing namespaces for a sub namespace.
|
|
14
27
|
|
|
15
|
-
|
|
16
28
|
## Example:
|
|
17
29
|
|
|
18
30
|
For usage see the [tests](./test) or the example below.
|
|
@@ -23,7 +35,8 @@ var debug = require('')();
|
|
|
23
35
|
// debug.save('namespace');
|
|
24
36
|
// debug.enable(debug.load())
|
|
25
37
|
debug = debug('namespace'); // debugger in the namespace
|
|
26
|
-
debug(function(){return '
|
|
38
|
+
debug(function(){return 'something to log' + someLargeHarryString;});
|
|
39
|
+
debug(() => 'something to log ${someLargeHarryString}');
|
|
27
40
|
debug('small out'); // prints namespace small out
|
|
28
41
|
var childDbg = debug.spawn('child'); // debugger in the namespace:child
|
|
29
42
|
childDbg('small out'); // prints namespace:child small out
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "debug-fabulous",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "visionmedia debug extensions rolled into one",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
"author": "Nicholas McCready",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"debug": "
|
|
24
|
-
"memoizee": "
|
|
25
|
-
"object-assign": "4.
|
|
23
|
+
"debug": "3.X",
|
|
24
|
+
"memoizee": "0.4.X",
|
|
25
|
+
"object-assign": "4.X"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"JSONStream": "1.X",
|
|
29
|
+
"chai": "4.X",
|
|
30
|
+
"eslint": "4.X",
|
|
30
31
|
"hook-std": "0.X",
|
|
31
|
-
"memwatch-next": "
|
|
32
|
-
"mocha": "
|
|
32
|
+
"memwatch-next": "0.3.X",
|
|
33
|
+
"mocha": "4.X"
|
|
33
34
|
}
|
|
34
35
|
}
|
package/src/lazy-eval.js
CHANGED
|
@@ -16,28 +16,24 @@ function _resolveOutput(func, bindThis) {
|
|
|
16
16
|
objectAssign(wrapped, func);
|
|
17
17
|
|
|
18
18
|
return wrapped;
|
|
19
|
-
}
|
|
20
|
-
|
|
19
|
+
}
|
|
21
20
|
|
|
22
21
|
function wrapEval(_debug) {
|
|
23
|
-
|
|
24
22
|
var debugOrig = _debug;
|
|
25
|
-
var noop = function(){};
|
|
26
23
|
|
|
27
24
|
function debug(namespace) {
|
|
28
|
-
|
|
25
|
+
function noop() {}
|
|
29
26
|
var instance = debugOrig(namespace);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
/*
|
|
28
|
+
If we're not enabled then don't attempt to log anything.
|
|
29
|
+
Therefore when a debug namespace wraps its debug in a
|
|
30
|
+
closure then it never allocates anything but the function itself
|
|
31
|
+
*/
|
|
32
|
+
if (!instance.enabled) {
|
|
34
33
|
objectAssign(noop, instance);
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
instance = _resolveOutput(instance);
|
|
34
|
+
return noop;
|
|
39
35
|
}
|
|
40
|
-
return instance;
|
|
36
|
+
return _resolveOutput(instance);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
var debugMemoized = memoize(debug);
|
package/src/spawn.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
function spawnFactory(_namespace, _debugFabFactory) {
|
|
2
|
-
var memoize = require('memoizee');
|
|
3
2
|
var namespace = _namespace || '';
|
|
4
3
|
var debugFabFactory = _debugFabFactory;
|
|
5
4
|
|
|
@@ -7,6 +6,13 @@ function spawnFactory(_namespace, _debugFabFactory) {
|
|
|
7
6
|
debugFabFactory = require('./debugFabFactory')();
|
|
8
7
|
}
|
|
9
8
|
|
|
9
|
+
function spawn(ns) {
|
|
10
|
+
// this is this.debug (from Debugger)
|
|
11
|
+
var dbg = new Debugger(this.namespace, ns);
|
|
12
|
+
|
|
13
|
+
return dbg.debug;
|
|
14
|
+
};
|
|
15
|
+
|
|
10
16
|
function Debugger(_base, _ns){
|
|
11
17
|
var base = _base || '';
|
|
12
18
|
var ns = _ns || '';
|
|
@@ -15,17 +21,9 @@ function spawnFactory(_namespace, _debugFabFactory) {
|
|
|
15
21
|
var debug = debugFabFactory(newNs);
|
|
16
22
|
|
|
17
23
|
this.debug = debug;
|
|
18
|
-
this.debug.spawn =
|
|
24
|
+
this.debug.spawn = spawn;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
Debugger.prototype.spawn = function(ns) {
|
|
22
|
-
var dbg = new Debugger(this.namespace, ns);
|
|
23
|
-
|
|
24
|
-
return dbg.debug;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
Debugger.prototype.spawn = memoize(Debugger.prototype.spawn);
|
|
28
|
-
|
|
29
27
|
var rootDebug = (new Debugger(namespace)).debug;
|
|
30
28
|
|
|
31
29
|
return rootDebug;
|