@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.
Files changed (141) hide show
  1. package/esm.mjs +21 -11
  2. package/lib/assess/policy/propagators.json +4 -0
  3. package/lib/assess/policy/signatures.json +5 -0
  4. package/lib/assess/propagators/fastify-static/allowed-path.js +85 -0
  5. package/lib/contrast.js +1 -1
  6. package/lib/core/rewrite/index.js +2 -2
  7. package/node_modules/@colors/colors/LICENSE +26 -0
  8. package/node_modules/@colors/colors/README.md +219 -0
  9. package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
  10. package/node_modules/@colors/colors/examples/safe-string.js +80 -0
  11. package/node_modules/@colors/colors/index.d.ts +136 -0
  12. package/node_modules/@colors/colors/lib/colors.js +211 -0
  13. package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
  14. package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
  15. package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
  16. package/node_modules/@colors/colors/lib/index.js +13 -0
  17. package/node_modules/@colors/colors/lib/maps/america.js +10 -0
  18. package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
  19. package/node_modules/@colors/colors/lib/maps/random.js +11 -0
  20. package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
  21. package/node_modules/@colors/colors/lib/styles.js +95 -0
  22. package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
  23. package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
  24. package/node_modules/@colors/colors/package.json +49 -0
  25. package/node_modules/@colors/colors/safe.d.ts +48 -0
  26. package/node_modules/@colors/colors/safe.js +10 -0
  27. package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
  28. package/node_modules/@dabh/diagnostics/README.md +16 -16
  29. package/node_modules/@dabh/diagnostics/package.json +9 -9
  30. package/node_modules/color/README.md +9 -0
  31. package/node_modules/color/index.js +4 -1
  32. package/node_modules/color/package.json +8 -8
  33. package/node_modules/color-string/README.md +6 -2
  34. package/node_modules/color-string/index.js +21 -13
  35. package/node_modules/color-string/package.json +4 -4
  36. package/node_modules/colorspace/package.json +5 -5
  37. package/node_modules/fecha/dist/fecha.min.js +1 -1
  38. package/node_modules/fecha/dist/fecha.min.js.map +1 -0
  39. package/node_modules/fecha/lib/fecha.d.ts +2 -2
  40. package/node_modules/fecha/lib/fecha.js +35 -18
  41. package/node_modules/fecha/lib/fecha.js.map +1 -0
  42. package/node_modules/fecha/lib/fecha.umd.js +35 -18
  43. package/node_modules/fecha/lib/fecha.umd.js.map +1 -0
  44. package/node_modules/fecha/package.json +9 -10
  45. package/node_modules/fecha/src/fecha.ts +524 -0
  46. package/node_modules/logform/.eslintrc +1 -1
  47. package/node_modules/logform/CHANGELOG.md +24 -0
  48. package/node_modules/logform/README.md +15 -17
  49. package/node_modules/logform/browser.js +3 -1
  50. package/node_modules/logform/cli.js +1 -1
  51. package/node_modules/logform/colorize.js +2 -2
  52. package/node_modules/logform/dist/browser.js +8 -2
  53. package/node_modules/logform/dist/cli.js +2 -2
  54. package/node_modules/logform/dist/colorize.js +5 -5
  55. package/node_modules/logform/dist/errors.js +1 -1
  56. package/node_modules/logform/dist/format.js +9 -5
  57. package/node_modules/logform/dist/index.js +53 -20
  58. package/node_modules/logform/dist/json.js +7 -6
  59. package/node_modules/logform/dist/logstash.js +1 -1
  60. package/node_modules/logform/dist/pad-levels.js +4 -4
  61. package/node_modules/logform/dist/printf.js +1 -1
  62. package/node_modules/logform/dist/simple.js +1 -1
  63. package/node_modules/logform/dist/splat.js +2 -2
  64. package/node_modules/logform/dist/uncolorize.js +1 -1
  65. package/node_modules/logform/errors.js +1 -1
  66. package/node_modules/logform/index.d.ts +36 -0
  67. package/node_modules/logform/index.js +19 -20
  68. package/node_modules/logform/json.js +7 -7
  69. package/node_modules/logform/logstash.js +1 -1
  70. package/node_modules/logform/package.json +10 -9
  71. package/node_modules/logform/simple.js +1 -1
  72. package/node_modules/logform/uncolorize.js +1 -1
  73. package/node_modules/safe-stable-stringify/CHANGELOG.md +75 -0
  74. package/node_modules/safe-stable-stringify/LICENSE +21 -0
  75. package/node_modules/safe-stable-stringify/esm/package.json +4 -0
  76. package/node_modules/safe-stable-stringify/esm/wrapper.js +6 -0
  77. package/node_modules/safe-stable-stringify/index.d.ts +18 -0
  78. package/node_modules/safe-stable-stringify/index.js +618 -0
  79. package/node_modules/safe-stable-stringify/package.json +69 -0
  80. package/node_modules/safe-stable-stringify/readme.md +170 -0
  81. package/node_modules/safe-stable-stringify/tsconfig.json +22 -0
  82. package/node_modules/winston/LICENSE +18 -18
  83. package/node_modules/winston/README.md +1231 -1230
  84. package/node_modules/winston/dist/winston/common.js +10 -10
  85. package/node_modules/winston/dist/winston/config/index.js +17 -17
  86. package/node_modules/winston/dist/winston/container.js +46 -46
  87. package/node_modules/winston/dist/winston/create-logger.js +28 -24
  88. package/node_modules/winston/dist/winston/exception-handler.js +49 -49
  89. package/node_modules/winston/dist/winston/exception-stream.js +27 -27
  90. package/node_modules/winston/dist/winston/logger.js +152 -138
  91. package/node_modules/winston/dist/winston/profiler.js +22 -22
  92. package/node_modules/winston/dist/winston/rejection-handler.js +54 -54
  93. package/node_modules/winston/dist/winston/tail-file.js +14 -14
  94. package/node_modules/winston/dist/winston/transports/console.js +31 -31
  95. package/node_modules/winston/dist/winston/transports/file.js +101 -101
  96. package/node_modules/winston/dist/winston/transports/http.js +119 -41
  97. package/node_modules/winston/dist/winston/transports/index.js +17 -17
  98. package/node_modules/winston/dist/winston/transports/stream.js +24 -24
  99. package/node_modules/winston/dist/winston.js +91 -97
  100. package/node_modules/winston/index.d.ts +213 -193
  101. package/node_modules/winston/lib/winston/common.js +61 -61
  102. package/node_modules/winston/lib/winston/config/index.d.ts +99 -98
  103. package/node_modules/winston/lib/winston/config/index.js +35 -35
  104. package/node_modules/winston/lib/winston/container.js +114 -114
  105. package/node_modules/winston/lib/winston/create-logger.js +104 -104
  106. package/node_modules/winston/lib/winston/exception-handler.js +245 -245
  107. package/node_modules/winston/lib/winston/exception-stream.js +54 -54
  108. package/node_modules/winston/lib/winston/logger.js +676 -667
  109. package/node_modules/winston/lib/winston/profiler.js +51 -51
  110. package/node_modules/winston/lib/winston/rejection-handler.js +251 -251
  111. package/node_modules/winston/lib/winston/tail-file.js +124 -124
  112. package/node_modules/winston/lib/winston/transports/console.js +117 -117
  113. package/node_modules/winston/lib/winston/transports/file.js +695 -695
  114. package/node_modules/winston/lib/winston/transports/http.js +267 -202
  115. package/node_modules/winston/lib/winston/transports/index.d.ts +103 -100
  116. package/node_modules/winston/lib/winston/transports/index.js +56 -56
  117. package/node_modules/winston/lib/winston/transports/stream.js +63 -63
  118. package/node_modules/winston/lib/winston.js +176 -182
  119. package/node_modules/winston/node_modules/winston-transport/.babelrc +3 -0
  120. package/node_modules/winston/node_modules/winston-transport/.eslintrc +7 -0
  121. package/node_modules/winston/node_modules/winston-transport/.gitattributes +1 -0
  122. package/node_modules/winston/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
  123. package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
  124. package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
  125. package/node_modules/winston/node_modules/winston-transport/CHANGELOG.md +126 -0
  126. package/node_modules/winston/node_modules/winston-transport/LICENSE +22 -0
  127. package/node_modules/winston/node_modules/winston-transport/README.md +50 -0
  128. package/node_modules/winston/node_modules/winston-transport/dist/index.js +215 -0
  129. package/node_modules/winston/node_modules/winston-transport/dist/legacy.js +116 -0
  130. package/node_modules/winston/node_modules/winston-transport/index.d.ts +39 -0
  131. package/node_modules/winston/node_modules/winston-transport/index.js +215 -0
  132. package/node_modules/winston/node_modules/winston-transport/legacy.js +119 -0
  133. package/node_modules/winston/node_modules/winston-transport/package.json +56 -0
  134. package/node_modules/winston/package.json +76 -75
  135. package/package.json +6 -4
  136. package/node_modules/@dabh/diagnostics/example.png +0 -0
  137. package/node_modules/color-string/CHANGELOG.md +0 -18
  138. package/node_modules/colorspace/test.js +0 -14
  139. package/node_modules/fecha/CHANGELOG.md +0 -67
  140. package/node_modules/logform/.travis.yml +0 -17
  141. package/node_modules/winston/CHANGELOG.md +0 -560
@@ -1,51 +1,51 @@
1
- /**
2
- * profiler.js: TODO: add file header description.
3
- *
4
- * (C) 2010 Charlie Robbins
5
- * MIT LICENCE
6
- */
7
-
8
- 'use strict';
9
-
10
- /**
11
- * TODO: add class description.
12
- * @type {Profiler}
13
- * @private
14
- */
15
- module.exports = class Profiler {
16
- /**
17
- * Constructor function for the Profiler instance used by
18
- * `Logger.prototype.startTimer`. When done is called the timer will finish
19
- * and log the duration.
20
- * @param {!Logger} logger - TODO: add param description.
21
- * @private
22
- */
23
- constructor(logger) {
24
- if (!logger) {
25
- throw new Error('Logger is required for profiling.');
26
- }
27
-
28
- this.logger = logger;
29
- this.start = Date.now();
30
- }
31
-
32
- /**
33
- * Ends the current timer (i.e. Profiler) instance and logs the `msg` along
34
- * with the duration since creation.
35
- * @returns {mixed} - TODO: add return description.
36
- * @private
37
- */
38
- done(...args) {
39
- if (typeof args[args.length - 1] === 'function') {
40
- // eslint-disable-next-line no-console
41
- console.warn('Callback function no longer supported as of winston@3.0.0');
42
- args.pop();
43
- }
44
-
45
- const info = typeof args[args.length - 1] === 'object' ? args.pop() : {};
46
- info.level = info.level || 'info';
47
- info.durationMs = (Date.now()) - this.start;
48
-
49
- return this.logger.write(info);
50
- }
51
- };
1
+ /**
2
+ * profiler.js: TODO: add file header description.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ /**
11
+ * TODO: add class description.
12
+ * @type {Profiler}
13
+ * @private
14
+ */
15
+ module.exports = class Profiler {
16
+ /**
17
+ * Constructor function for the Profiler instance used by
18
+ * `Logger.prototype.startTimer`. When done is called the timer will finish
19
+ * and log the duration.
20
+ * @param {!Logger} logger - TODO: add param description.
21
+ * @private
22
+ */
23
+ constructor(logger) {
24
+ if (!logger) {
25
+ throw new Error('Logger is required for profiling.');
26
+ }
27
+
28
+ this.logger = logger;
29
+ this.start = Date.now();
30
+ }
31
+
32
+ /**
33
+ * Ends the current timer (i.e. Profiler) instance and logs the `msg` along
34
+ * with the duration since creation.
35
+ * @returns {mixed} - TODO: add return description.
36
+ * @private
37
+ */
38
+ done(...args) {
39
+ if (typeof args[args.length - 1] === 'function') {
40
+ // eslint-disable-next-line no-console
41
+ console.warn('Callback function no longer supported as of winston@3.0.0');
42
+ args.pop();
43
+ }
44
+
45
+ const info = typeof args[args.length - 1] === 'object' ? args.pop() : {};
46
+ info.level = info.level || 'info';
47
+ info.durationMs = (Date.now()) - this.start;
48
+
49
+ return this.logger.write(info);
50
+ }
51
+ };
@@ -1,251 +1,251 @@
1
- /**
2
- * exception-handler.js: Object for handling uncaughtException events.
3
- *
4
- * (C) 2010 Charlie Robbins
5
- * MIT LICENCE
6
- */
7
-
8
- 'use strict';
9
-
10
- const os = require('os');
11
- const asyncForEach = require('async/forEach');
12
- const debug = require('@dabh/diagnostics')('winston:rejection');
13
- const once = require('one-time');
14
- const stackTrace = require('stack-trace');
15
- const ExceptionStream = require('./exception-stream');
16
-
17
- /**
18
- * Object for handling unhandledRejection events.
19
- * @type {RejectionHandler}
20
- */
21
- module.exports = class RejectionHandler {
22
- /**
23
- * TODO: add contructor description
24
- * @param {!Logger} logger - TODO: add param description
25
- */
26
- constructor(logger) {
27
- if (!logger) {
28
- throw new Error('Logger is required to handle rejections');
29
- }
30
-
31
- this.logger = logger;
32
- this.handlers = new Map();
33
- }
34
-
35
- /**
36
- * Handles `unhandledRejection` events for the current process by adding any
37
- * handlers passed in.
38
- * @returns {undefined}
39
- */
40
- handle(...args) {
41
- args.forEach(arg => {
42
- if (Array.isArray(arg)) {
43
- return arg.forEach(handler => this._addHandler(handler));
44
- }
45
-
46
- this._addHandler(arg);
47
- });
48
-
49
- if (!this.catcher) {
50
- this.catcher = this._unhandledRejection.bind(this);
51
- process.on('unhandledRejection', this.catcher);
52
- }
53
- }
54
-
55
- /**
56
- * Removes any handlers to `unhandledRejection` events for the current
57
- * process. This does not modify the state of the `this.handlers` set.
58
- * @returns {undefined}
59
- */
60
- unhandle() {
61
- if (this.catcher) {
62
- process.removeListener('unhandledRejection', this.catcher);
63
- this.catcher = false;
64
-
65
- Array.from(this.handlers.values()).forEach(wrapper =>
66
- this.logger.unpipe(wrapper)
67
- );
68
- }
69
- }
70
-
71
- /**
72
- * TODO: add method description
73
- * @param {Error} err - Error to get information about.
74
- * @returns {mixed} - TODO: add return description.
75
- */
76
- getAllInfo(err) {
77
- let { message } = err;
78
- if (!message && typeof err === 'string') {
79
- message = err;
80
- }
81
-
82
- return {
83
- error: err,
84
- // TODO (indexzero): how do we configure this?
85
- level: 'error',
86
- message: [
87
- `unhandledRejection: ${message || '(no error message)'}`,
88
- err.stack || ' No stack trace'
89
- ].join('\n'),
90
- stack: err.stack,
91
- exception: true,
92
- date: new Date().toString(),
93
- process: this.getProcessInfo(),
94
- os: this.getOsInfo(),
95
- trace: this.getTrace(err)
96
- };
97
- }
98
-
99
- /**
100
- * Gets all relevant process information for the currently running process.
101
- * @returns {mixed} - TODO: add return description.
102
- */
103
- getProcessInfo() {
104
- return {
105
- pid: process.pid,
106
- uid: process.getuid ? process.getuid() : null,
107
- gid: process.getgid ? process.getgid() : null,
108
- cwd: process.cwd(),
109
- execPath: process.execPath,
110
- version: process.version,
111
- argv: process.argv,
112
- memoryUsage: process.memoryUsage()
113
- };
114
- }
115
-
116
- /**
117
- * Gets all relevant OS information for the currently running process.
118
- * @returns {mixed} - TODO: add return description.
119
- */
120
- getOsInfo() {
121
- return {
122
- loadavg: os.loadavg(),
123
- uptime: os.uptime()
124
- };
125
- }
126
-
127
- /**
128
- * Gets a stack trace for the specified error.
129
- * @param {mixed} err - TODO: add param description.
130
- * @returns {mixed} - TODO: add return description.
131
- */
132
- getTrace(err) {
133
- const trace = err ? stackTrace.parse(err) : stackTrace.get();
134
- return trace.map(site => {
135
- return {
136
- column: site.getColumnNumber(),
137
- file: site.getFileName(),
138
- function: site.getFunctionName(),
139
- line: site.getLineNumber(),
140
- method: site.getMethodName(),
141
- native: site.isNative()
142
- };
143
- });
144
- }
145
-
146
- /**
147
- * Helper method to add a transport as an exception handler.
148
- * @param {Transport} handler - The transport to add as an exception handler.
149
- * @returns {void}
150
- */
151
- _addHandler(handler) {
152
- if (!this.handlers.has(handler)) {
153
- handler.handleRejections = true;
154
- const wrapper = new ExceptionStream(handler);
155
- this.handlers.set(handler, wrapper);
156
- this.logger.pipe(wrapper);
157
- }
158
- }
159
-
160
- /**
161
- * Logs all relevant information around the `err` and exits the current
162
- * process.
163
- * @param {Error} err - Error to handle
164
- * @returns {mixed} - TODO: add return description.
165
- * @private
166
- */
167
- _unhandledRejection(err) {
168
- const info = this.getAllInfo(err);
169
- const handlers = this._getRejectionHandlers();
170
- // Calculate if we should exit on this error
171
- let doExit =
172
- typeof this.logger.exitOnError === 'function'
173
- ? this.logger.exitOnError(err)
174
- : this.logger.exitOnError;
175
- let timeout;
176
-
177
- if (!handlers.length && doExit) {
178
- // eslint-disable-next-line no-console
179
- console.warn('winston: exitOnError cannot be true with no rejection handlers.');
180
- // eslint-disable-next-line no-console
181
- console.warn('winston: not exiting process.');
182
- doExit = false;
183
- }
184
-
185
- function gracefulExit() {
186
- debug('doExit', doExit);
187
- debug('process._exiting', process._exiting);
188
-
189
- if (doExit && !process._exiting) {
190
- // Remark: Currently ignoring any rejections from transports when
191
- // catching unhandled rejections.
192
- if (timeout) {
193
- clearTimeout(timeout);
194
- }
195
- // eslint-disable-next-line no-process-exit
196
- process.exit(1);
197
- }
198
- }
199
-
200
- if (!handlers || handlers.length === 0) {
201
- return process.nextTick(gracefulExit);
202
- }
203
-
204
- // Log to all transports attempting to listen for when they are completed.
205
- asyncForEach(
206
- handlers,
207
- (handler, next) => {
208
- const done = once(next);
209
- const transport = handler.transport || handler;
210
-
211
- // Debug wrapping so that we can inspect what's going on under the covers.
212
- function onDone(event) {
213
- return () => {
214
- debug(event);
215
- done();
216
- };
217
- }
218
-
219
- transport._ending = true;
220
- transport.once('finish', onDone('finished'));
221
- transport.once('error', onDone('error'));
222
- },
223
- () => doExit && gracefulExit()
224
- );
225
-
226
- this.logger.log(info);
227
-
228
- // If exitOnError is true, then only allow the logging of exceptions to
229
- // take up to `3000ms`.
230
- if (doExit) {
231
- timeout = setTimeout(gracefulExit, 3000);
232
- }
233
- }
234
-
235
- /**
236
- * Returns the list of transports and exceptionHandlers for this instance.
237
- * @returns {Array} - List of transports and exceptionHandlers for this
238
- * instance.
239
- * @private
240
- */
241
- _getRejectionHandlers() {
242
- // Remark (indexzero): since `logger.transports` returns all of the pipes
243
- // from the _readableState of the stream we actually get the join of the
244
- // explicit handlers and the implicit transports with
245
- // `handleRejections: true`
246
- return this.logger.transports.filter(wrap => {
247
- const transport = wrap.transport || wrap;
248
- return transport.handleRejections;
249
- });
250
- }
251
- };
1
+ /**
2
+ * exception-handler.js: Object for handling uncaughtException events.
3
+ *
4
+ * (C) 2010 Charlie Robbins
5
+ * MIT LICENCE
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const os = require('os');
11
+ const asyncForEach = require('async/forEach');
12
+ const debug = require('@dabh/diagnostics')('winston:rejection');
13
+ const once = require('one-time');
14
+ const stackTrace = require('stack-trace');
15
+ const ExceptionStream = require('./exception-stream');
16
+
17
+ /**
18
+ * Object for handling unhandledRejection events.
19
+ * @type {RejectionHandler}
20
+ */
21
+ module.exports = class RejectionHandler {
22
+ /**
23
+ * TODO: add contructor description
24
+ * @param {!Logger} logger - TODO: add param description
25
+ */
26
+ constructor(logger) {
27
+ if (!logger) {
28
+ throw new Error('Logger is required to handle rejections');
29
+ }
30
+
31
+ this.logger = logger;
32
+ this.handlers = new Map();
33
+ }
34
+
35
+ /**
36
+ * Handles `unhandledRejection` events for the current process by adding any
37
+ * handlers passed in.
38
+ * @returns {undefined}
39
+ */
40
+ handle(...args) {
41
+ args.forEach(arg => {
42
+ if (Array.isArray(arg)) {
43
+ return arg.forEach(handler => this._addHandler(handler));
44
+ }
45
+
46
+ this._addHandler(arg);
47
+ });
48
+
49
+ if (!this.catcher) {
50
+ this.catcher = this._unhandledRejection.bind(this);
51
+ process.on('unhandledRejection', this.catcher);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Removes any handlers to `unhandledRejection` events for the current
57
+ * process. This does not modify the state of the `this.handlers` set.
58
+ * @returns {undefined}
59
+ */
60
+ unhandle() {
61
+ if (this.catcher) {
62
+ process.removeListener('unhandledRejection', this.catcher);
63
+ this.catcher = false;
64
+
65
+ Array.from(this.handlers.values()).forEach(wrapper =>
66
+ this.logger.unpipe(wrapper)
67
+ );
68
+ }
69
+ }
70
+
71
+ /**
72
+ * TODO: add method description
73
+ * @param {Error} err - Error to get information about.
74
+ * @returns {mixed} - TODO: add return description.
75
+ */
76
+ getAllInfo(err) {
77
+ let message = null;
78
+ if (err) {
79
+ message = typeof err === 'string' ? err : err.message;
80
+ }
81
+
82
+ return {
83
+ error: err,
84
+ // TODO (indexzero): how do we configure this?
85
+ level: 'error',
86
+ message: [
87
+ `unhandledRejection: ${message || '(no error message)'}`,
88
+ err && err.stack || ' No stack trace'
89
+ ].join('\n'),
90
+ stack: err && err.stack,
91
+ exception: true,
92
+ date: new Date().toString(),
93
+ process: this.getProcessInfo(),
94
+ os: this.getOsInfo(),
95
+ trace: this.getTrace(err)
96
+ };
97
+ }
98
+
99
+ /**
100
+ * Gets all relevant process information for the currently running process.
101
+ * @returns {mixed} - TODO: add return description.
102
+ */
103
+ getProcessInfo() {
104
+ return {
105
+ pid: process.pid,
106
+ uid: process.getuid ? process.getuid() : null,
107
+ gid: process.getgid ? process.getgid() : null,
108
+ cwd: process.cwd(),
109
+ execPath: process.execPath,
110
+ version: process.version,
111
+ argv: process.argv,
112
+ memoryUsage: process.memoryUsage()
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Gets all relevant OS information for the currently running process.
118
+ * @returns {mixed} - TODO: add return description.
119
+ */
120
+ getOsInfo() {
121
+ return {
122
+ loadavg: os.loadavg(),
123
+ uptime: os.uptime()
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Gets a stack trace for the specified error.
129
+ * @param {mixed} err - TODO: add param description.
130
+ * @returns {mixed} - TODO: add return description.
131
+ */
132
+ getTrace(err) {
133
+ const trace = err ? stackTrace.parse(err) : stackTrace.get();
134
+ return trace.map(site => {
135
+ return {
136
+ column: site.getColumnNumber(),
137
+ file: site.getFileName(),
138
+ function: site.getFunctionName(),
139
+ line: site.getLineNumber(),
140
+ method: site.getMethodName(),
141
+ native: site.isNative()
142
+ };
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Helper method to add a transport as an exception handler.
148
+ * @param {Transport} handler - The transport to add as an exception handler.
149
+ * @returns {void}
150
+ */
151
+ _addHandler(handler) {
152
+ if (!this.handlers.has(handler)) {
153
+ handler.handleRejections = true;
154
+ const wrapper = new ExceptionStream(handler);
155
+ this.handlers.set(handler, wrapper);
156
+ this.logger.pipe(wrapper);
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Logs all relevant information around the `err` and exits the current
162
+ * process.
163
+ * @param {Error} err - Error to handle
164
+ * @returns {mixed} - TODO: add return description.
165
+ * @private
166
+ */
167
+ _unhandledRejection(err) {
168
+ const info = this.getAllInfo(err);
169
+ const handlers = this._getRejectionHandlers();
170
+ // Calculate if we should exit on this error
171
+ let doExit =
172
+ typeof this.logger.exitOnError === 'function'
173
+ ? this.logger.exitOnError(err)
174
+ : this.logger.exitOnError;
175
+ let timeout;
176
+
177
+ if (!handlers.length && doExit) {
178
+ // eslint-disable-next-line no-console
179
+ console.warn('winston: exitOnError cannot be true with no rejection handlers.');
180
+ // eslint-disable-next-line no-console
181
+ console.warn('winston: not exiting process.');
182
+ doExit = false;
183
+ }
184
+
185
+ function gracefulExit() {
186
+ debug('doExit', doExit);
187
+ debug('process._exiting', process._exiting);
188
+
189
+ if (doExit && !process._exiting) {
190
+ // Remark: Currently ignoring any rejections from transports when
191
+ // catching unhandled rejections.
192
+ if (timeout) {
193
+ clearTimeout(timeout);
194
+ }
195
+ // eslint-disable-next-line no-process-exit
196
+ process.exit(1);
197
+ }
198
+ }
199
+
200
+ if (!handlers || handlers.length === 0) {
201
+ return process.nextTick(gracefulExit);
202
+ }
203
+
204
+ // Log to all transports attempting to listen for when they are completed.
205
+ asyncForEach(
206
+ handlers,
207
+ (handler, next) => {
208
+ const done = once(next);
209
+ const transport = handler.transport || handler;
210
+
211
+ // Debug wrapping so that we can inspect what's going on under the covers.
212
+ function onDone(event) {
213
+ return () => {
214
+ debug(event);
215
+ done();
216
+ };
217
+ }
218
+
219
+ transport._ending = true;
220
+ transport.once('finish', onDone('finished'));
221
+ transport.once('error', onDone('error'));
222
+ },
223
+ () => doExit && gracefulExit()
224
+ );
225
+
226
+ this.logger.log(info);
227
+
228
+ // If exitOnError is true, then only allow the logging of exceptions to
229
+ // take up to `3000ms`.
230
+ if (doExit) {
231
+ timeout = setTimeout(gracefulExit, 3000);
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Returns the list of transports and exceptionHandlers for this instance.
237
+ * @returns {Array} - List of transports and exceptionHandlers for this
238
+ * instance.
239
+ * @private
240
+ */
241
+ _getRejectionHandlers() {
242
+ // Remark (indexzero): since `logger.transports` returns all of the pipes
243
+ // from the _readableState of the stream we actually get the join of the
244
+ // explicit handlers and the implicit transports with
245
+ // `handleRejections: true`
246
+ return this.logger.transports.filter(wrap => {
247
+ const transport = wrap.transport || wrap;
248
+ return transport.handleRejections;
249
+ });
250
+ }
251
+ };