* Adds the transport to this logger instance by piping to it. * @param {mixed} transport - TODO: add param description. * @returns {Logger} - TODO: add return description.
(transport)
| 366 | * @returns {Logger} - TODO: add return description. |
| 367 | */ |
| 368 | add(transport) { |
| 369 | // Support backwards compatibility with all existing `winston < 3.x.x` |
| 370 | // transports which meet one of two criteria: |
| 371 | // 1. They inherit from winston.Transport in < 3.x.x which is NOT a stream. |
| 372 | // 2. They expose a log method which has a length greater than 2 (i.e. more then |
| 373 | // just `log(info, callback)`. |
| 374 | const target = |
| 375 | !isStream(transport) || transport.log.length > 2 |
| 376 | ? new LegacyTransportStream({ transport }) |
| 377 | : transport; |
| 378 | |
| 379 | if (!target._writableState || !target._writableState.objectMode) { |
| 380 | throw new Error( |
| 381 | 'Transports must WritableStreams in objectMode. Set { objectMode: true }.' |
| 382 | ); |
| 383 | } |
| 384 | |
| 385 | // Listen for the `error` event and the `warn` event on the new Transport. |
| 386 | this._onEvent('error', target); |
| 387 | this._onEvent('warn', target); |
| 388 | this.pipe(target); |
| 389 | |
| 390 | if (transport.handleExceptions) { |
| 391 | this.exceptions.handle(); |
| 392 | } |
| 393 | |
| 394 | if (transport.handleRejections) { |
| 395 | this.rejections.handle(); |
| 396 | } |
| 397 | |
| 398 | return this; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Removes the transport from this logger instance by unpiping from it. |
no test coverage detected