@contrast/agent 4.16.2 → 4.18.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/assess/sources/index.js +26 -5
- package/lib/cli-rewriter/index.js +1 -1
- package/lib/contrast.js +1 -1
- package/lib/core/config/options.js +14 -1
- package/lib/core/config/util.js +39 -11
- package/lib/core/rewrite/index.js +2 -2
- package/lib/protect/service.js +2 -0
- package/lib/util/trace-util.js +5 -4
- 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 +9 -6
- 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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# winston-transport
|
|
2
|
+
|
|
3
|
+
The base `TransportStream` implementation for `winston >= 3`. Use these to
|
|
4
|
+
write ecosystem Transports for `winston`.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
``` js
|
|
9
|
+
const Transport = require('winston-transport');
|
|
10
|
+
const util = require('util');
|
|
11
|
+
|
|
12
|
+
//
|
|
13
|
+
// Inherit from `winston-transport` so you can take advantage
|
|
14
|
+
// of the base functionality and `.exceptions.handle()`.
|
|
15
|
+
//
|
|
16
|
+
module.exports = class CustomTransport extends Transport {
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
super(opts);
|
|
19
|
+
|
|
20
|
+
//
|
|
21
|
+
// Consume any custom options here. e.g.:
|
|
22
|
+
// - Connection information for databases
|
|
23
|
+
// - Authentication information for APIs (e.g. loggly, papertrail,
|
|
24
|
+
// logentries, etc.).
|
|
25
|
+
//
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
log(info, callback) {
|
|
29
|
+
setImmediate(() => {
|
|
30
|
+
this.emit('logged', info);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Perform the writing to the remote service
|
|
34
|
+
|
|
35
|
+
callback();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Tests
|
|
41
|
+
|
|
42
|
+
Tests are written with `mocha`, `nyc`, `assume`, and
|
|
43
|
+
`abstract-winston-transport`. They can be run with `npm`:
|
|
44
|
+
|
|
45
|
+
``` bash
|
|
46
|
+
npm test
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
##### Author: [Charlie Robbins](https://github.com/indexzero)
|
|
50
|
+
##### LICENSE: MIT
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var Writable = require('readable-stream/lib/_stream_writable.js');
|
|
5
|
+
|
|
6
|
+
var _require = require('triple-beam'),
|
|
7
|
+
LEVEL = _require.LEVEL;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructor function for the TransportStream. This is the base prototype
|
|
11
|
+
* that all `winston >= 3` transports should inherit from.
|
|
12
|
+
* @param {Object} options - Options for this TransportStream instance
|
|
13
|
+
* @param {String} options.level - Highest level according to RFC5424.
|
|
14
|
+
* @param {Boolean} options.handleExceptions - If true, info with
|
|
15
|
+
* { exception: true } will be written.
|
|
16
|
+
* @param {Function} options.log - Custom log function for simple Transport
|
|
17
|
+
* creation
|
|
18
|
+
* @param {Function} options.close - Called on "unpipe" from parent.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var TransportStream = module.exports = function TransportStream() {
|
|
23
|
+
var _this = this;
|
|
24
|
+
|
|
25
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
|
+
|
|
27
|
+
Writable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
|
|
28
|
+
|
|
29
|
+
this.format = options.format;
|
|
30
|
+
this.level = options.level;
|
|
31
|
+
this.handleExceptions = options.handleExceptions;
|
|
32
|
+
this.handleRejections = options.handleRejections;
|
|
33
|
+
this.silent = options.silent;
|
|
34
|
+
|
|
35
|
+
if (options.log) this.log = options.log;
|
|
36
|
+
if (options.logv) this.logv = options.logv;
|
|
37
|
+
if (options.close) this.close = options.close;
|
|
38
|
+
|
|
39
|
+
// Get the levels from the source we are piped from.
|
|
40
|
+
this.once('pipe', function (logger) {
|
|
41
|
+
// Remark (indexzero): this bookkeeping can only support multiple
|
|
42
|
+
// Logger parents with the same `levels`. This comes into play in
|
|
43
|
+
// the `winston.Container` code in which `container.add` takes
|
|
44
|
+
// a fully realized set of options with pre-constructed TransportStreams.
|
|
45
|
+
_this.levels = logger.levels;
|
|
46
|
+
_this.parent = logger;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// If and/or when the transport is removed from this instance
|
|
50
|
+
this.once('unpipe', function (src) {
|
|
51
|
+
// Remark (indexzero): this bookkeeping can only support multiple
|
|
52
|
+
// Logger parents with the same `levels`. This comes into play in
|
|
53
|
+
// the `winston.Container` code in which `container.add` takes
|
|
54
|
+
// a fully realized set of options with pre-constructed TransportStreams.
|
|
55
|
+
if (src === _this.parent) {
|
|
56
|
+
_this.parent = null;
|
|
57
|
+
if (_this.close) {
|
|
58
|
+
_this.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* Inherit from Writeable using Node.js built-ins
|
|
66
|
+
*/
|
|
67
|
+
util.inherits(TransportStream, Writable);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Writes the info object to our transport instance.
|
|
71
|
+
* @param {mixed} info - TODO: add param description.
|
|
72
|
+
* @param {mixed} enc - TODO: add param description.
|
|
73
|
+
* @param {function} callback - TODO: add param description.
|
|
74
|
+
* @returns {undefined}
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
TransportStream.prototype._write = function _write(info, enc, callback) {
|
|
78
|
+
if (this.silent || info.exception === true && !this.handleExceptions) {
|
|
79
|
+
return callback(null);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Remark: This has to be handled in the base transport now because we
|
|
83
|
+
// cannot conditionally write to our pipe targets as stream. We always
|
|
84
|
+
// prefer any explicit level set on the Transport itself falling back to
|
|
85
|
+
// any level set on the parent.
|
|
86
|
+
var level = this.level || this.parent && this.parent.level;
|
|
87
|
+
|
|
88
|
+
if (!level || this.levels[level] >= this.levels[info[LEVEL]]) {
|
|
89
|
+
if (info && !this.format) {
|
|
90
|
+
return this.log(info, callback);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var errState = void 0;
|
|
94
|
+
var transformed = void 0;
|
|
95
|
+
|
|
96
|
+
// We trap(and re-throw) any errors generated by the user-provided format, but also
|
|
97
|
+
// guarantee that the streams callback is invoked so that we can continue flowing.
|
|
98
|
+
try {
|
|
99
|
+
transformed = this.format.transform(Object.assign({}, info), this.format.options);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
errState = err;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (errState || !transformed) {
|
|
105
|
+
// eslint-disable-next-line callback-return
|
|
106
|
+
callback();
|
|
107
|
+
if (errState) throw errState;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return this.log(transformed, callback);
|
|
112
|
+
}
|
|
113
|
+
this._writableState.sync = false;
|
|
114
|
+
return callback(null);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Writes the batch of info objects (i.e. "object chunks") to our transport
|
|
119
|
+
* instance after performing any necessary filtering.
|
|
120
|
+
* @param {mixed} chunks - TODO: add params description.
|
|
121
|
+
* @param {function} callback - TODO: add params description.
|
|
122
|
+
* @returns {mixed} - TODO: add returns description.
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
TransportStream.prototype._writev = function _writev(chunks, callback) {
|
|
126
|
+
if (this.logv) {
|
|
127
|
+
var infos = chunks.filter(this._accept, this);
|
|
128
|
+
if (!infos.length) {
|
|
129
|
+
return callback(null);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Remark (indexzero): from a performance perspective if Transport
|
|
133
|
+
// implementers do choose to implement logv should we make it their
|
|
134
|
+
// responsibility to invoke their format?
|
|
135
|
+
return this.logv(infos, callback);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (var i = 0; i < chunks.length; i++) {
|
|
139
|
+
if (!this._accept(chunks[i])) continue;
|
|
140
|
+
|
|
141
|
+
if (chunks[i].chunk && !this.format) {
|
|
142
|
+
this.log(chunks[i].chunk, chunks[i].callback);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var errState = void 0;
|
|
147
|
+
var transformed = void 0;
|
|
148
|
+
|
|
149
|
+
// We trap(and re-throw) any errors generated by the user-provided format, but also
|
|
150
|
+
// guarantee that the streams callback is invoked so that we can continue flowing.
|
|
151
|
+
try {
|
|
152
|
+
transformed = this.format.transform(Object.assign({}, chunks[i].chunk), this.format.options);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
errState = err;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (errState || !transformed) {
|
|
158
|
+
// eslint-disable-next-line callback-return
|
|
159
|
+
chunks[i].callback();
|
|
160
|
+
if (errState) {
|
|
161
|
+
// eslint-disable-next-line callback-return
|
|
162
|
+
callback(null);
|
|
163
|
+
throw errState;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
this.log(transformed, chunks[i].callback);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return callback(null);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Predicate function that returns true if the specfied `info` on the
|
|
175
|
+
* WriteReq, `write`, should be passed down into the derived
|
|
176
|
+
* TransportStream's I/O via `.log(info, callback)`.
|
|
177
|
+
* @param {WriteReq} write - winston@3 Node.js WriteReq for the `info` object
|
|
178
|
+
* representing the log message.
|
|
179
|
+
* @returns {Boolean} - Value indicating if the `write` should be accepted &
|
|
180
|
+
* logged.
|
|
181
|
+
*/
|
|
182
|
+
TransportStream.prototype._accept = function _accept(write) {
|
|
183
|
+
var info = write.chunk;
|
|
184
|
+
if (this.silent) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// We always prefer any explicit level set on the Transport itself
|
|
189
|
+
// falling back to any level set on the parent.
|
|
190
|
+
var level = this.level || this.parent && this.parent.level;
|
|
191
|
+
|
|
192
|
+
// Immediately check the average case: log level filtering.
|
|
193
|
+
if (info.exception === true || !level || this.levels[level] >= this.levels[info[LEVEL]]) {
|
|
194
|
+
// Ensure the info object is valid based on `{ exception }`:
|
|
195
|
+
// 1. { handleExceptions: true }: all `info` objects are valid
|
|
196
|
+
// 2. { exception: false }: accepted by all transports.
|
|
197
|
+
if (this.handleExceptions || info.exception !== true) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return false;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* _nop is short for "No operation"
|
|
207
|
+
* @returns {Boolean} Intentionally false.
|
|
208
|
+
*/
|
|
209
|
+
TransportStream.prototype._nop = function _nop() {
|
|
210
|
+
// eslint-disable-next-line no-undefined
|
|
211
|
+
return void undefined;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// Expose legacy stream
|
|
215
|
+
module.exports.LegacyTransportStream = require('./legacy');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
|
|
5
|
+
var _require = require('triple-beam'),
|
|
6
|
+
LEVEL = _require.LEVEL;
|
|
7
|
+
|
|
8
|
+
var TransportStream = require('./');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Constructor function for the LegacyTransportStream. This is an internal
|
|
12
|
+
* wrapper `winston >= 3` uses to wrap older transports implementing
|
|
13
|
+
* log(level, message, meta).
|
|
14
|
+
* @param {Object} options - Options for this TransportStream instance.
|
|
15
|
+
* @param {Transpot} options.transport - winston@2 or older Transport to wrap.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
var LegacyTransportStream = module.exports = function LegacyTransportStream() {
|
|
19
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20
|
+
|
|
21
|
+
TransportStream.call(this, options);
|
|
22
|
+
if (!options.transport || typeof options.transport.log !== 'function') {
|
|
23
|
+
throw new Error('Invalid transport, must be an object with a log method.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.transport = options.transport;
|
|
27
|
+
this.level = this.level || options.transport.level;
|
|
28
|
+
this.handleExceptions = this.handleExceptions || options.transport.handleExceptions;
|
|
29
|
+
|
|
30
|
+
// Display our deprecation notice.
|
|
31
|
+
this._deprecated();
|
|
32
|
+
|
|
33
|
+
// Properly bubble up errors from the transport to the
|
|
34
|
+
// LegacyTransportStream instance, but only once no matter how many times
|
|
35
|
+
// this transport is shared.
|
|
36
|
+
function transportError(err) {
|
|
37
|
+
this.emit('error', err, this.transport);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!this.transport.__winstonError) {
|
|
41
|
+
this.transport.__winstonError = transportError.bind(this);
|
|
42
|
+
this.transport.on('error', this.transport.__winstonError);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* Inherit from TransportStream using Node.js built-ins
|
|
48
|
+
*/
|
|
49
|
+
util.inherits(LegacyTransportStream, TransportStream);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Writes the info object to our transport instance.
|
|
53
|
+
* @param {mixed} info - TODO: add param description.
|
|
54
|
+
* @param {mixed} enc - TODO: add param description.
|
|
55
|
+
* @param {function} callback - TODO: add param description.
|
|
56
|
+
* @returns {undefined}
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
LegacyTransportStream.prototype._write = function _write(info, enc, callback) {
|
|
60
|
+
if (this.silent || info.exception === true && !this.handleExceptions) {
|
|
61
|
+
return callback(null);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Remark: This has to be handled in the base transport now because we
|
|
65
|
+
// cannot conditionally write to our pipe targets as stream.
|
|
66
|
+
if (!this.level || this.levels[this.level] >= this.levels[info[LEVEL]]) {
|
|
67
|
+
this.transport.log(info[LEVEL], info.message, info, this._nop);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
callback(null);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Writes the batch of info objects (i.e. "object chunks") to our transport
|
|
75
|
+
* instance after performing any necessary filtering.
|
|
76
|
+
* @param {mixed} chunks - TODO: add params description.
|
|
77
|
+
* @param {function} callback - TODO: add params description.
|
|
78
|
+
* @returns {mixed} - TODO: add returns description.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
LegacyTransportStream.prototype._writev = function _writev(chunks, callback) {
|
|
82
|
+
for (var i = 0; i < chunks.length; i++) {
|
|
83
|
+
if (this._accept(chunks[i])) {
|
|
84
|
+
this.transport.log(chunks[i].chunk[LEVEL], chunks[i].chunk.message, chunks[i].chunk, this._nop);
|
|
85
|
+
chunks[i].callback();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return callback(null);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Displays a deprecation notice. Defined as a function so it can be
|
|
94
|
+
* overriden in tests.
|
|
95
|
+
* @returns {undefined}
|
|
96
|
+
*/
|
|
97
|
+
LegacyTransportStream.prototype._deprecated = function _deprecated() {
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.error([this.transport.name + ' is a legacy winston transport. Consider upgrading: ', '- Upgrade docs: https://github.com/winstonjs/winston/blob/master/UPGRADE-3.0.md'].join('\n'));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Clean up error handling state on the legacy transport associated
|
|
104
|
+
* with this instance.
|
|
105
|
+
* @returns {undefined}
|
|
106
|
+
*/
|
|
107
|
+
LegacyTransportStream.prototype.close = function close() {
|
|
108
|
+
if (this.transport.close) {
|
|
109
|
+
this.transport.close();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (this.transport.__winstonError) {
|
|
113
|
+
this.transport.removeListener('error', this.transport.__winstonError);
|
|
114
|
+
this.transport.__winstonError = null;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Type definitions for winston-transport 3.0
|
|
2
|
+
// Project: https://github.com/winstonjs/winston-transport
|
|
3
|
+
// Definitions by: DABH <https://github.com/DABH>
|
|
4
|
+
// Definitions: https://github.com/winstonjs/winston-transport
|
|
5
|
+
|
|
6
|
+
/// <reference types="node" />
|
|
7
|
+
|
|
8
|
+
import * as stream from 'stream';
|
|
9
|
+
import * as logform from 'logform';
|
|
10
|
+
|
|
11
|
+
declare class TransportStream extends stream.Writable {
|
|
12
|
+
public format?: logform.Format;
|
|
13
|
+
public level?: string;
|
|
14
|
+
public silent?: boolean;
|
|
15
|
+
public handleExceptions?: boolean;
|
|
16
|
+
public handleRejections?: boolean;
|
|
17
|
+
|
|
18
|
+
constructor(opts?: TransportStream.TransportStreamOptions);
|
|
19
|
+
|
|
20
|
+
public log?(info: any, next: () => void): any;
|
|
21
|
+
public logv?(info: any, next: () => void): any;
|
|
22
|
+
public close?(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare namespace TransportStream {
|
|
26
|
+
interface TransportStreamOptions {
|
|
27
|
+
format?: logform.Format;
|
|
28
|
+
level?: string;
|
|
29
|
+
silent?: boolean;
|
|
30
|
+
handleExceptions?: boolean;
|
|
31
|
+
handleRejections?: boolean;
|
|
32
|
+
|
|
33
|
+
log?(info: any, next: () => void): any;
|
|
34
|
+
logv?(info: any, next: () => void): any;
|
|
35
|
+
close?(): void;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export = TransportStream;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const util = require('util');
|
|
4
|
+
const Writable = require('readable-stream/lib/_stream_writable.js');
|
|
5
|
+
const { LEVEL } = require('triple-beam');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Constructor function for the TransportStream. This is the base prototype
|
|
9
|
+
* that all `winston >= 3` transports should inherit from.
|
|
10
|
+
* @param {Object} options - Options for this TransportStream instance
|
|
11
|
+
* @param {String} options.level - Highest level according to RFC5424.
|
|
12
|
+
* @param {Boolean} options.handleExceptions - If true, info with
|
|
13
|
+
* { exception: true } will be written.
|
|
14
|
+
* @param {Function} options.log - Custom log function for simple Transport
|
|
15
|
+
* creation
|
|
16
|
+
* @param {Function} options.close - Called on "unpipe" from parent.
|
|
17
|
+
*/
|
|
18
|
+
const TransportStream = module.exports = function TransportStream(options = {}) {
|
|
19
|
+
Writable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
|
|
20
|
+
|
|
21
|
+
this.format = options.format;
|
|
22
|
+
this.level = options.level;
|
|
23
|
+
this.handleExceptions = options.handleExceptions;
|
|
24
|
+
this.handleRejections = options.handleRejections;
|
|
25
|
+
this.silent = options.silent;
|
|
26
|
+
|
|
27
|
+
if (options.log) this.log = options.log;
|
|
28
|
+
if (options.logv) this.logv = options.logv;
|
|
29
|
+
if (options.close) this.close = options.close;
|
|
30
|
+
|
|
31
|
+
// Get the levels from the source we are piped from.
|
|
32
|
+
this.once('pipe', logger => {
|
|
33
|
+
// Remark (indexzero): this bookkeeping can only support multiple
|
|
34
|
+
// Logger parents with the same `levels`. This comes into play in
|
|
35
|
+
// the `winston.Container` code in which `container.add` takes
|
|
36
|
+
// a fully realized set of options with pre-constructed TransportStreams.
|
|
37
|
+
this.levels = logger.levels;
|
|
38
|
+
this.parent = logger;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// If and/or when the transport is removed from this instance
|
|
42
|
+
this.once('unpipe', src => {
|
|
43
|
+
// Remark (indexzero): this bookkeeping can only support multiple
|
|
44
|
+
// Logger parents with the same `levels`. This comes into play in
|
|
45
|
+
// the `winston.Container` code in which `container.add` takes
|
|
46
|
+
// a fully realized set of options with pre-constructed TransportStreams.
|
|
47
|
+
if (src === this.parent) {
|
|
48
|
+
this.parent = null;
|
|
49
|
+
if (this.close) {
|
|
50
|
+
this.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* Inherit from Writeable using Node.js built-ins
|
|
58
|
+
*/
|
|
59
|
+
util.inherits(TransportStream, Writable);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Writes the info object to our transport instance.
|
|
63
|
+
* @param {mixed} info - TODO: add param description.
|
|
64
|
+
* @param {mixed} enc - TODO: add param description.
|
|
65
|
+
* @param {function} callback - TODO: add param description.
|
|
66
|
+
* @returns {undefined}
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
TransportStream.prototype._write = function _write(info, enc, callback) {
|
|
70
|
+
if (this.silent || (info.exception === true && !this.handleExceptions)) {
|
|
71
|
+
return callback(null);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Remark: This has to be handled in the base transport now because we
|
|
75
|
+
// cannot conditionally write to our pipe targets as stream. We always
|
|
76
|
+
// prefer any explicit level set on the Transport itself falling back to
|
|
77
|
+
// any level set on the parent.
|
|
78
|
+
const level = this.level || (this.parent && this.parent.level);
|
|
79
|
+
|
|
80
|
+
if (!level || this.levels[level] >= this.levels[info[LEVEL]]) {
|
|
81
|
+
if (info && !this.format) {
|
|
82
|
+
return this.log(info, callback);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let errState;
|
|
86
|
+
let transformed;
|
|
87
|
+
|
|
88
|
+
// We trap(and re-throw) any errors generated by the user-provided format, but also
|
|
89
|
+
// guarantee that the streams callback is invoked so that we can continue flowing.
|
|
90
|
+
try {
|
|
91
|
+
transformed = this.format.transform(Object.assign({}, info), this.format.options);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
errState = err;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (errState || !transformed) {
|
|
97
|
+
// eslint-disable-next-line callback-return
|
|
98
|
+
callback();
|
|
99
|
+
if (errState) throw errState;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return this.log(transformed, callback);
|
|
104
|
+
}
|
|
105
|
+
this._writableState.sync = false;
|
|
106
|
+
return callback(null);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Writes the batch of info objects (i.e. "object chunks") to our transport
|
|
111
|
+
* instance after performing any necessary filtering.
|
|
112
|
+
* @param {mixed} chunks - TODO: add params description.
|
|
113
|
+
* @param {function} callback - TODO: add params description.
|
|
114
|
+
* @returns {mixed} - TODO: add returns description.
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
TransportStream.prototype._writev = function _writev(chunks, callback) {
|
|
118
|
+
if (this.logv) {
|
|
119
|
+
const infos = chunks.filter(this._accept, this);
|
|
120
|
+
if (!infos.length) {
|
|
121
|
+
return callback(null);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Remark (indexzero): from a performance perspective if Transport
|
|
125
|
+
// implementers do choose to implement logv should we make it their
|
|
126
|
+
// responsibility to invoke their format?
|
|
127
|
+
return this.logv(infos, callback);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
131
|
+
if (!this._accept(chunks[i])) continue;
|
|
132
|
+
|
|
133
|
+
if (chunks[i].chunk && !this.format) {
|
|
134
|
+
this.log(chunks[i].chunk, chunks[i].callback);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let errState;
|
|
139
|
+
let transformed;
|
|
140
|
+
|
|
141
|
+
// We trap(and re-throw) any errors generated by the user-provided format, but also
|
|
142
|
+
// guarantee that the streams callback is invoked so that we can continue flowing.
|
|
143
|
+
try {
|
|
144
|
+
transformed = this.format.transform(
|
|
145
|
+
Object.assign({}, chunks[i].chunk),
|
|
146
|
+
this.format.options
|
|
147
|
+
);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
errState = err;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (errState || !transformed) {
|
|
153
|
+
// eslint-disable-next-line callback-return
|
|
154
|
+
chunks[i].callback();
|
|
155
|
+
if (errState) {
|
|
156
|
+
// eslint-disable-next-line callback-return
|
|
157
|
+
callback(null);
|
|
158
|
+
throw errState;
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
this.log(transformed, chunks[i].callback);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return callback(null);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Predicate function that returns true if the specfied `info` on the
|
|
170
|
+
* WriteReq, `write`, should be passed down into the derived
|
|
171
|
+
* TransportStream's I/O via `.log(info, callback)`.
|
|
172
|
+
* @param {WriteReq} write - winston@3 Node.js WriteReq for the `info` object
|
|
173
|
+
* representing the log message.
|
|
174
|
+
* @returns {Boolean} - Value indicating if the `write` should be accepted &
|
|
175
|
+
* logged.
|
|
176
|
+
*/
|
|
177
|
+
TransportStream.prototype._accept = function _accept(write) {
|
|
178
|
+
const info = write.chunk;
|
|
179
|
+
if (this.silent) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// We always prefer any explicit level set on the Transport itself
|
|
184
|
+
// falling back to any level set on the parent.
|
|
185
|
+
const level = this.level || (this.parent && this.parent.level);
|
|
186
|
+
|
|
187
|
+
// Immediately check the average case: log level filtering.
|
|
188
|
+
if (
|
|
189
|
+
info.exception === true ||
|
|
190
|
+
!level ||
|
|
191
|
+
this.levels[level] >= this.levels[info[LEVEL]]
|
|
192
|
+
) {
|
|
193
|
+
// Ensure the info object is valid based on `{ exception }`:
|
|
194
|
+
// 1. { handleExceptions: true }: all `info` objects are valid
|
|
195
|
+
// 2. { exception: false }: accepted by all transports.
|
|
196
|
+
if (this.handleExceptions || info.exception !== true) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return false;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* _nop is short for "No operation"
|
|
206
|
+
* @returns {Boolean} Intentionally false.
|
|
207
|
+
*/
|
|
208
|
+
TransportStream.prototype._nop = function _nop() {
|
|
209
|
+
// eslint-disable-next-line no-undefined
|
|
210
|
+
return void undefined;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
// Expose legacy stream
|
|
215
|
+
module.exports.LegacyTransportStream = require('./legacy');
|