@contrast/agent 4.16.2 → 4.17.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/esm.mjs +21 -11
- package/lib/assess/policy/propagators.json +4 -0
- package/lib/assess/policy/signatures.json +5 -0
- package/lib/assess/propagators/fastify-static/allowed-path.js +85 -0
- package/lib/contrast.js +1 -1
- package/lib/core/rewrite/index.js +2 -2
- package/node_modules/@colors/colors/LICENSE +26 -0
- package/node_modules/@colors/colors/README.md +219 -0
- package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
- package/node_modules/@colors/colors/examples/safe-string.js +80 -0
- package/node_modules/@colors/colors/index.d.ts +136 -0
- package/node_modules/@colors/colors/lib/colors.js +211 -0
- package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
- package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
- package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
- package/node_modules/@colors/colors/lib/index.js +13 -0
- package/node_modules/@colors/colors/lib/maps/america.js +10 -0
- package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
- package/node_modules/@colors/colors/lib/maps/random.js +11 -0
- package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
- package/node_modules/@colors/colors/lib/styles.js +95 -0
- package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
- package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
- package/node_modules/@colors/colors/package.json +49 -0
- package/node_modules/@colors/colors/safe.d.ts +48 -0
- package/node_modules/@colors/colors/safe.js +10 -0
- package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
- package/node_modules/@dabh/diagnostics/README.md +16 -16
- package/node_modules/@dabh/diagnostics/package.json +9 -9
- package/node_modules/color/README.md +9 -0
- package/node_modules/color/index.js +4 -1
- package/node_modules/color/package.json +8 -8
- package/node_modules/color-string/README.md +6 -2
- package/node_modules/color-string/index.js +21 -13
- package/node_modules/color-string/package.json +4 -4
- package/node_modules/colorspace/package.json +5 -5
- package/node_modules/fecha/dist/fecha.min.js +1 -1
- package/node_modules/fecha/dist/fecha.min.js.map +1 -0
- package/node_modules/fecha/lib/fecha.d.ts +2 -2
- package/node_modules/fecha/lib/fecha.js +35 -18
- package/node_modules/fecha/lib/fecha.js.map +1 -0
- package/node_modules/fecha/lib/fecha.umd.js +35 -18
- package/node_modules/fecha/lib/fecha.umd.js.map +1 -0
- package/node_modules/fecha/package.json +9 -10
- package/node_modules/fecha/src/fecha.ts +524 -0
- package/node_modules/logform/.eslintrc +1 -1
- package/node_modules/logform/CHANGELOG.md +24 -0
- package/node_modules/logform/README.md +15 -17
- package/node_modules/logform/browser.js +3 -1
- package/node_modules/logform/cli.js +1 -1
- package/node_modules/logform/colorize.js +2 -2
- package/node_modules/logform/dist/browser.js +8 -2
- package/node_modules/logform/dist/cli.js +2 -2
- package/node_modules/logform/dist/colorize.js +5 -5
- package/node_modules/logform/dist/errors.js +1 -1
- package/node_modules/logform/dist/format.js +9 -5
- package/node_modules/logform/dist/index.js +53 -20
- package/node_modules/logform/dist/json.js +7 -6
- package/node_modules/logform/dist/logstash.js +1 -1
- package/node_modules/logform/dist/pad-levels.js +4 -4
- package/node_modules/logform/dist/printf.js +1 -1
- package/node_modules/logform/dist/simple.js +1 -1
- package/node_modules/logform/dist/splat.js +2 -2
- package/node_modules/logform/dist/uncolorize.js +1 -1
- package/node_modules/logform/errors.js +1 -1
- package/node_modules/logform/index.d.ts +36 -0
- package/node_modules/logform/index.js +19 -20
- package/node_modules/logform/json.js +7 -7
- package/node_modules/logform/logstash.js +1 -1
- package/node_modules/logform/package.json +10 -9
- package/node_modules/logform/simple.js +1 -1
- package/node_modules/logform/uncolorize.js +1 -1
- package/node_modules/safe-stable-stringify/CHANGELOG.md +75 -0
- package/node_modules/safe-stable-stringify/LICENSE +21 -0
- package/node_modules/safe-stable-stringify/esm/package.json +4 -0
- package/node_modules/safe-stable-stringify/esm/wrapper.js +6 -0
- package/node_modules/safe-stable-stringify/index.d.ts +18 -0
- package/node_modules/safe-stable-stringify/index.js +618 -0
- package/node_modules/safe-stable-stringify/package.json +69 -0
- package/node_modules/safe-stable-stringify/readme.md +170 -0
- package/node_modules/safe-stable-stringify/tsconfig.json +22 -0
- package/node_modules/winston/LICENSE +18 -18
- package/node_modules/winston/README.md +1231 -1230
- package/node_modules/winston/dist/winston/common.js +10 -10
- package/node_modules/winston/dist/winston/config/index.js +17 -17
- package/node_modules/winston/dist/winston/container.js +46 -46
- package/node_modules/winston/dist/winston/create-logger.js +28 -24
- package/node_modules/winston/dist/winston/exception-handler.js +49 -49
- package/node_modules/winston/dist/winston/exception-stream.js +27 -27
- package/node_modules/winston/dist/winston/logger.js +152 -138
- package/node_modules/winston/dist/winston/profiler.js +22 -22
- package/node_modules/winston/dist/winston/rejection-handler.js +54 -54
- package/node_modules/winston/dist/winston/tail-file.js +14 -14
- package/node_modules/winston/dist/winston/transports/console.js +31 -31
- package/node_modules/winston/dist/winston/transports/file.js +101 -101
- package/node_modules/winston/dist/winston/transports/http.js +119 -41
- package/node_modules/winston/dist/winston/transports/index.js +17 -17
- package/node_modules/winston/dist/winston/transports/stream.js +24 -24
- package/node_modules/winston/dist/winston.js +91 -97
- package/node_modules/winston/index.d.ts +213 -193
- package/node_modules/winston/lib/winston/common.js +61 -61
- package/node_modules/winston/lib/winston/config/index.d.ts +99 -98
- package/node_modules/winston/lib/winston/config/index.js +35 -35
- package/node_modules/winston/lib/winston/container.js +114 -114
- package/node_modules/winston/lib/winston/create-logger.js +104 -104
- package/node_modules/winston/lib/winston/exception-handler.js +245 -245
- package/node_modules/winston/lib/winston/exception-stream.js +54 -54
- package/node_modules/winston/lib/winston/logger.js +676 -667
- package/node_modules/winston/lib/winston/profiler.js +51 -51
- package/node_modules/winston/lib/winston/rejection-handler.js +251 -251
- package/node_modules/winston/lib/winston/tail-file.js +124 -124
- package/node_modules/winston/lib/winston/transports/console.js +117 -117
- package/node_modules/winston/lib/winston/transports/file.js +695 -695
- package/node_modules/winston/lib/winston/transports/http.js +267 -202
- package/node_modules/winston/lib/winston/transports/index.d.ts +103 -100
- package/node_modules/winston/lib/winston/transports/index.js +56 -56
- package/node_modules/winston/lib/winston/transports/stream.js +63 -63
- package/node_modules/winston/lib/winston.js +176 -182
- package/node_modules/winston/node_modules/winston-transport/.babelrc +3 -0
- package/node_modules/winston/node_modules/winston-transport/.eslintrc +7 -0
- package/node_modules/winston/node_modules/winston-transport/.gitattributes +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/CHANGELOG.md +126 -0
- package/node_modules/winston/node_modules/winston-transport/LICENSE +22 -0
- package/node_modules/winston/node_modules/winston-transport/README.md +50 -0
- package/node_modules/winston/node_modules/winston-transport/dist/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/dist/legacy.js +116 -0
- package/node_modules/winston/node_modules/winston-transport/index.d.ts +39 -0
- package/node_modules/winston/node_modules/winston-transport/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/legacy.js +119 -0
- package/node_modules/winston/node_modules/winston-transport/package.json +56 -0
- package/node_modules/winston/package.json +76 -75
- package/package.json +6 -4
- package/node_modules/@dabh/diagnostics/example.png +0 -0
- package/node_modules/color-string/CHANGELOG.md +0 -18
- package/node_modules/colorspace/test.js +0 -14
- package/node_modules/fecha/CHANGELOG.md +0 -67
- package/node_modules/logform/.travis.yml +0 -17
- package/node_modules/winston/CHANGELOG.md +0 -560
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* tail-file.js: TODO: add file header description.
|
|
3
|
-
*
|
|
4
|
-
* (C) 2010 Charlie Robbins
|
|
5
|
-
* MIT LICENCE
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const { StringDecoder } = require('string_decoder');
|
|
12
|
-
const { Stream } = require('readable-stream');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Simple no-op function.
|
|
16
|
-
* @returns {undefined}
|
|
17
|
-
*/
|
|
18
|
-
function noop() {}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* TODO: add function description.
|
|
22
|
-
* @param {Object} options - Options for tail.
|
|
23
|
-
* @param {function} iter - Iterator function to execute on every line.
|
|
24
|
-
* `tail -f` a file. Options must include file.
|
|
25
|
-
* @returns {mixed} - TODO: add return description.
|
|
26
|
-
*/
|
|
27
|
-
module.exports = (options, iter) => {
|
|
28
|
-
const buffer = Buffer.alloc(64 * 1024);
|
|
29
|
-
const decode = new StringDecoder('utf8');
|
|
30
|
-
const stream = new Stream();
|
|
31
|
-
let buff = '';
|
|
32
|
-
let pos = 0;
|
|
33
|
-
let row = 0;
|
|
34
|
-
|
|
35
|
-
if (options.start === -1) {
|
|
36
|
-
delete options.start;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
stream.readable = true;
|
|
40
|
-
stream.destroy = () => {
|
|
41
|
-
stream.destroyed = true;
|
|
42
|
-
stream.emit('end');
|
|
43
|
-
stream.emit('close');
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
fs.open(options.file, 'a+', '0644', (err, fd) => {
|
|
47
|
-
if (err) {
|
|
48
|
-
if (!iter) {
|
|
49
|
-
stream.emit('error', err);
|
|
50
|
-
} else {
|
|
51
|
-
iter(err);
|
|
52
|
-
}
|
|
53
|
-
stream.destroy();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
(function read() {
|
|
58
|
-
if (stream.destroyed) {
|
|
59
|
-
fs.close(fd, noop);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return fs.read(fd, buffer, 0, buffer.length, pos, (error, bytes) => {
|
|
64
|
-
if (error) {
|
|
65
|
-
if (!iter) {
|
|
66
|
-
stream.emit('error', error);
|
|
67
|
-
} else {
|
|
68
|
-
iter(error);
|
|
69
|
-
}
|
|
70
|
-
stream.destroy();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!bytes) {
|
|
75
|
-
if (buff) {
|
|
76
|
-
// eslint-disable-next-line eqeqeq
|
|
77
|
-
if (options.start == null || row > options.start) {
|
|
78
|
-
if (!iter) {
|
|
79
|
-
stream.emit('line', buff);
|
|
80
|
-
} else {
|
|
81
|
-
iter(null, buff);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
row++;
|
|
85
|
-
buff = '';
|
|
86
|
-
}
|
|
87
|
-
return setTimeout(read, 1000);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let data = decode.write(buffer.slice(0, bytes));
|
|
91
|
-
if (!iter) {
|
|
92
|
-
stream.emit('data', data);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
data = (buff + data).split(/\n+/);
|
|
96
|
-
|
|
97
|
-
const l = data.length - 1;
|
|
98
|
-
let i = 0;
|
|
99
|
-
|
|
100
|
-
for (; i < l; i++) {
|
|
101
|
-
// eslint-disable-next-line eqeqeq
|
|
102
|
-
if (options.start == null || row > options.start) {
|
|
103
|
-
if (!iter) {
|
|
104
|
-
stream.emit('line', data[i]);
|
|
105
|
-
} else {
|
|
106
|
-
iter(null, data[i]);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
row++;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
buff = data[l];
|
|
113
|
-
pos += bytes;
|
|
114
|
-
return read();
|
|
115
|
-
});
|
|
116
|
-
}());
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
if (!iter) {
|
|
120
|
-
return stream;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return stream.destroy;
|
|
124
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* tail-file.js: TODO: add file header description.
|
|
3
|
+
*
|
|
4
|
+
* (C) 2010 Charlie Robbins
|
|
5
|
+
* MIT LICENCE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const { StringDecoder } = require('string_decoder');
|
|
12
|
+
const { Stream } = require('readable-stream');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Simple no-op function.
|
|
16
|
+
* @returns {undefined}
|
|
17
|
+
*/
|
|
18
|
+
function noop() {}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* TODO: add function description.
|
|
22
|
+
* @param {Object} options - Options for tail.
|
|
23
|
+
* @param {function} iter - Iterator function to execute on every line.
|
|
24
|
+
* `tail -f` a file. Options must include file.
|
|
25
|
+
* @returns {mixed} - TODO: add return description.
|
|
26
|
+
*/
|
|
27
|
+
module.exports = (options, iter) => {
|
|
28
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
29
|
+
const decode = new StringDecoder('utf8');
|
|
30
|
+
const stream = new Stream();
|
|
31
|
+
let buff = '';
|
|
32
|
+
let pos = 0;
|
|
33
|
+
let row = 0;
|
|
34
|
+
|
|
35
|
+
if (options.start === -1) {
|
|
36
|
+
delete options.start;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
stream.readable = true;
|
|
40
|
+
stream.destroy = () => {
|
|
41
|
+
stream.destroyed = true;
|
|
42
|
+
stream.emit('end');
|
|
43
|
+
stream.emit('close');
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
fs.open(options.file, 'a+', '0644', (err, fd) => {
|
|
47
|
+
if (err) {
|
|
48
|
+
if (!iter) {
|
|
49
|
+
stream.emit('error', err);
|
|
50
|
+
} else {
|
|
51
|
+
iter(err);
|
|
52
|
+
}
|
|
53
|
+
stream.destroy();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
(function read() {
|
|
58
|
+
if (stream.destroyed) {
|
|
59
|
+
fs.close(fd, noop);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return fs.read(fd, buffer, 0, buffer.length, pos, (error, bytes) => {
|
|
64
|
+
if (error) {
|
|
65
|
+
if (!iter) {
|
|
66
|
+
stream.emit('error', error);
|
|
67
|
+
} else {
|
|
68
|
+
iter(error);
|
|
69
|
+
}
|
|
70
|
+
stream.destroy();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!bytes) {
|
|
75
|
+
if (buff) {
|
|
76
|
+
// eslint-disable-next-line eqeqeq
|
|
77
|
+
if (options.start == null || row > options.start) {
|
|
78
|
+
if (!iter) {
|
|
79
|
+
stream.emit('line', buff);
|
|
80
|
+
} else {
|
|
81
|
+
iter(null, buff);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
row++;
|
|
85
|
+
buff = '';
|
|
86
|
+
}
|
|
87
|
+
return setTimeout(read, 1000);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let data = decode.write(buffer.slice(0, bytes));
|
|
91
|
+
if (!iter) {
|
|
92
|
+
stream.emit('data', data);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
data = (buff + data).split(/\n+/);
|
|
96
|
+
|
|
97
|
+
const l = data.length - 1;
|
|
98
|
+
let i = 0;
|
|
99
|
+
|
|
100
|
+
for (; i < l; i++) {
|
|
101
|
+
// eslint-disable-next-line eqeqeq
|
|
102
|
+
if (options.start == null || row > options.start) {
|
|
103
|
+
if (!iter) {
|
|
104
|
+
stream.emit('line', data[i]);
|
|
105
|
+
} else {
|
|
106
|
+
iter(null, data[i]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
row++;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
buff = data[l];
|
|
113
|
+
pos += bytes;
|
|
114
|
+
return read();
|
|
115
|
+
});
|
|
116
|
+
}());
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (!iter) {
|
|
120
|
+
return stream;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return stream.destroy;
|
|
124
|
+
};
|
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
/*
|
|
3
|
-
* console.js: Transport for outputting to the console.
|
|
4
|
-
*
|
|
5
|
-
* (C) 2010 Charlie Robbins
|
|
6
|
-
* MIT LICENCE
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
'use strict';
|
|
10
|
-
|
|
11
|
-
const os = require('os');
|
|
12
|
-
const { LEVEL, MESSAGE } = require('triple-beam');
|
|
13
|
-
const TransportStream = require('winston-transport');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Transport for outputting to the console.
|
|
17
|
-
* @type {Console}
|
|
18
|
-
* @extends {TransportStream}
|
|
19
|
-
*/
|
|
20
|
-
module.exports = class Console extends TransportStream {
|
|
21
|
-
/**
|
|
22
|
-
* Constructor function for the Console transport object responsible for
|
|
23
|
-
* persisting log messages and metadata to a terminal or TTY.
|
|
24
|
-
* @param {!Object} [options={}] - Options for this instance.
|
|
25
|
-
*/
|
|
26
|
-
constructor(options = {}) {
|
|
27
|
-
super(options);
|
|
28
|
-
|
|
29
|
-
// Expose the name of this Transport on the prototype
|
|
30
|
-
this.name = options.name || 'console';
|
|
31
|
-
this.stderrLevels = this._stringArrayToSet(options.stderrLevels);
|
|
32
|
-
this.consoleWarnLevels = this._stringArrayToSet(options.consoleWarnLevels);
|
|
33
|
-
this.eol = options.eol
|
|
34
|
-
|
|
35
|
-
this.setMaxListeners(30);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Core logging method exposed to Winston.
|
|
40
|
-
* @param {Object} info - TODO: add param description.
|
|
41
|
-
* @param {Function} callback - TODO: add param description.
|
|
42
|
-
* @returns {undefined}
|
|
43
|
-
*/
|
|
44
|
-
log(info, callback) {
|
|
45
|
-
setImmediate(() => this.emit('logged', info));
|
|
46
|
-
|
|
47
|
-
// Remark: what if there is no raw...?
|
|
48
|
-
if (this.stderrLevels[info[LEVEL]]) {
|
|
49
|
-
if (console._stderr) {
|
|
50
|
-
// Node.js maps `process.stderr` to `console._stderr`.
|
|
51
|
-
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
|
|
52
|
-
} else {
|
|
53
|
-
// console.error adds a newline
|
|
54
|
-
console.error(info[MESSAGE]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (callback) {
|
|
58
|
-
callback(); // eslint-disable-line callback-return
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
} else if (this.consoleWarnLevels[info[LEVEL]]) {
|
|
62
|
-
if (console._stderr) {
|
|
63
|
-
// Node.js maps `process.stderr` to `console._stderr`.
|
|
64
|
-
// in Node.js console.warn is an alias for console.error
|
|
65
|
-
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
|
|
66
|
-
} else {
|
|
67
|
-
// console.warn adds a newline
|
|
68
|
-
console.warn(info[MESSAGE]);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (callback) {
|
|
72
|
-
callback(); // eslint-disable-line callback-return
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (console._stdout) {
|
|
78
|
-
// Node.js maps `process.stdout` to `console._stdout`.
|
|
79
|
-
console._stdout.write(`${info[MESSAGE]}${this.eol}`);
|
|
80
|
-
} else {
|
|
81
|
-
// console.log adds a newline.
|
|
82
|
-
console.log(info[MESSAGE]);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (callback) {
|
|
86
|
-
callback(); // eslint-disable-line callback-return
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Returns a Set-like object with strArray's elements as keys (each with the
|
|
92
|
-
* value true).
|
|
93
|
-
* @param {Array} strArray - Array of Set-elements as strings.
|
|
94
|
-
* @param {?string} [errMsg] - Custom error message thrown on invalid input.
|
|
95
|
-
* @returns {Object} - TODO: add return description.
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
98
|
-
_stringArrayToSet(strArray, errMsg) {
|
|
99
|
-
if (!strArray)
|
|
100
|
-
return {};
|
|
101
|
-
|
|
102
|
-
errMsg = errMsg || 'Cannot make set from type other than Array of string elements';
|
|
103
|
-
|
|
104
|
-
if (!Array.isArray(strArray)) {
|
|
105
|
-
throw new Error(errMsg);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return strArray.reduce((set, el) => {
|
|
109
|
-
if (typeof el !== 'string') {
|
|
110
|
-
throw new Error(errMsg);
|
|
111
|
-
}
|
|
112
|
-
set[el] = true;
|
|
113
|
-
|
|
114
|
-
return set;
|
|
115
|
-
}, {});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/*
|
|
3
|
+
* console.js: Transport for outputting to the console.
|
|
4
|
+
*
|
|
5
|
+
* (C) 2010 Charlie Robbins
|
|
6
|
+
* MIT LICENCE
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const { LEVEL, MESSAGE } = require('triple-beam');
|
|
13
|
+
const TransportStream = require('winston-transport');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Transport for outputting to the console.
|
|
17
|
+
* @type {Console}
|
|
18
|
+
* @extends {TransportStream}
|
|
19
|
+
*/
|
|
20
|
+
module.exports = class Console extends TransportStream {
|
|
21
|
+
/**
|
|
22
|
+
* Constructor function for the Console transport object responsible for
|
|
23
|
+
* persisting log messages and metadata to a terminal or TTY.
|
|
24
|
+
* @param {!Object} [options={}] - Options for this instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
super(options);
|
|
28
|
+
|
|
29
|
+
// Expose the name of this Transport on the prototype
|
|
30
|
+
this.name = options.name || 'console';
|
|
31
|
+
this.stderrLevels = this._stringArrayToSet(options.stderrLevels);
|
|
32
|
+
this.consoleWarnLevels = this._stringArrayToSet(options.consoleWarnLevels);
|
|
33
|
+
this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL;
|
|
34
|
+
|
|
35
|
+
this.setMaxListeners(30);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Core logging method exposed to Winston.
|
|
40
|
+
* @param {Object} info - TODO: add param description.
|
|
41
|
+
* @param {Function} callback - TODO: add param description.
|
|
42
|
+
* @returns {undefined}
|
|
43
|
+
*/
|
|
44
|
+
log(info, callback) {
|
|
45
|
+
setImmediate(() => this.emit('logged', info));
|
|
46
|
+
|
|
47
|
+
// Remark: what if there is no raw...?
|
|
48
|
+
if (this.stderrLevels[info[LEVEL]]) {
|
|
49
|
+
if (console._stderr) {
|
|
50
|
+
// Node.js maps `process.stderr` to `console._stderr`.
|
|
51
|
+
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
|
|
52
|
+
} else {
|
|
53
|
+
// console.error adds a newline
|
|
54
|
+
console.error(info[MESSAGE]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (callback) {
|
|
58
|
+
callback(); // eslint-disable-line callback-return
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
} else if (this.consoleWarnLevels[info[LEVEL]]) {
|
|
62
|
+
if (console._stderr) {
|
|
63
|
+
// Node.js maps `process.stderr` to `console._stderr`.
|
|
64
|
+
// in Node.js console.warn is an alias for console.error
|
|
65
|
+
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
|
|
66
|
+
} else {
|
|
67
|
+
// console.warn adds a newline
|
|
68
|
+
console.warn(info[MESSAGE]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (callback) {
|
|
72
|
+
callback(); // eslint-disable-line callback-return
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (console._stdout) {
|
|
78
|
+
// Node.js maps `process.stdout` to `console._stdout`.
|
|
79
|
+
console._stdout.write(`${info[MESSAGE]}${this.eol}`);
|
|
80
|
+
} else {
|
|
81
|
+
// console.log adds a newline.
|
|
82
|
+
console.log(info[MESSAGE]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (callback) {
|
|
86
|
+
callback(); // eslint-disable-line callback-return
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns a Set-like object with strArray's elements as keys (each with the
|
|
92
|
+
* value true).
|
|
93
|
+
* @param {Array} strArray - Array of Set-elements as strings.
|
|
94
|
+
* @param {?string} [errMsg] - Custom error message thrown on invalid input.
|
|
95
|
+
* @returns {Object} - TODO: add return description.
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
_stringArrayToSet(strArray, errMsg) {
|
|
99
|
+
if (!strArray)
|
|
100
|
+
return {};
|
|
101
|
+
|
|
102
|
+
errMsg = errMsg || 'Cannot make set from type other than Array of string elements';
|
|
103
|
+
|
|
104
|
+
if (!Array.isArray(strArray)) {
|
|
105
|
+
throw new Error(errMsg);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return strArray.reduce((set, el) => {
|
|
109
|
+
if (typeof el !== 'string') {
|
|
110
|
+
throw new Error(errMsg);
|
|
111
|
+
}
|
|
112
|
+
set[el] = true;
|
|
113
|
+
|
|
114
|
+
return set;
|
|
115
|
+
}, {});
|
|
116
|
+
}
|
|
117
|
+
};
|