1 | "use strict";
|
2 |
|
3 | var noop = require("es5-ext/function/noop")
|
4 | , objForEach = require("es5-ext/object/for-each")
|
5 | , d = require("d");
|
6 |
|
7 | module.exports = {
|
8 |
|
9 | isEnabled: d("ew", true),
|
10 |
|
11 |
|
12 | enable: d(function () { return this._setEnabledState(true); }),
|
13 |
|
14 |
|
15 | disable: d(function () { return this._setEnabledState(false); }),
|
16 |
|
17 | _setEnabledState: d(function (state) {
|
18 | var cache = [];
|
19 | this._setEnabledStateRecursively(state, cache);
|
20 | var result = {
|
21 | restore: function () {
|
22 | cache.forEach(function (data) {
|
23 | if (data.hasDirectSetting) data.logger.isEnabled = !state;
|
24 | else delete data.logger.isEnabled;
|
25 | });
|
26 | result.restore = noop;
|
27 | }
|
28 | };
|
29 | return result;
|
30 | }),
|
31 | _setEnabledStateRecursively: d(function (newState, cache) {
|
32 | if (this.isEnabled !== newState) {
|
33 | cache.push({ logger: this, hasDirectSetting: hasOwnProperty.call(this, "isEnabled") });
|
34 | this.isEnabled = newState;
|
35 | }
|
36 | objForEach(this._childNamespaceLoggers, function (namespacedLogger) {
|
37 | namespacedLogger._setEnabledStateRecursively(newState, cache);
|
38 | });
|
39 | })
|
40 | };
|