scope.js
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
var log = require('./log').log;
module.exports = scopeFactory;
/**
* @param {ElectronLog.ElectronLog} electronLog
* @return {ElectronLog.Scope}
*/
function scopeFactory(electronLog) {
scope.labelPadding = true;
scope.defaultLabel = '';
/** @private */
scope.maxLabelLength = 0;
/**
* @type {typeof getOptions}
* @package
*/
scope.getOptions = getOptions;
return scope;
function scope(label) {
var instance = {
label: label,
toJSON: function () {
return {
label: this.label,
};
},
};
electronLog.levels.forEach(function (level) {
instance[level] = log.bind(null, electronLog, {
level: level,
scope: instance,
});
});
instance.log = instance.info;
scope.maxLabelLength = Math.max(scope.maxLabelLength, label.length);
return instance;
}
function getOptions() {
return {
defaultLabel: scope.defaultLabel,
labelLength: getLabelLength(),
};
}
function getLabelLength() {
if (scope.labelPadding === true) {
return scope.maxLabelLength;
}
if (scope.labelPadding === false) {
return 0;
}
if (typeof scope.labelPadding === 'number') {
return scope.labelPadding;
}
return 0;
}
}