123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 'use strict';
- const util = require('util');
- const { LEVEL } = require('triple-beam');
- const TransportStream = require('./modern');
- const LegacyTransportStream = module.exports = function LegacyTransportStream(options = {}) {
- TransportStream.call(this, options);
- if (!options.transport || typeof options.transport.log !== 'function') {
- throw new Error('Invalid transport, must be an object with a log method.');
- }
- this.transport = options.transport;
- this.level = this.level || options.transport.level;
- this.handleExceptions = this.handleExceptions || options.transport.handleExceptions;
-
- this._deprecated();
-
-
-
- function transportError(err) {
- this.emit('error', err, this.transport);
- }
- if (!this.transport.__winstonError) {
- this.transport.__winstonError = transportError.bind(this);
- this.transport.on('error', this.transport.__winstonError);
- }
- };
- util.inherits(LegacyTransportStream, TransportStream);
- LegacyTransportStream.prototype._write = function _write(info, enc, callback) {
- if (this.silent || (info.exception === true && !this.handleExceptions)) {
- return callback(null);
- }
-
-
- if (!this.level || this.levels[this.level] >= this.levels[info[LEVEL]]) {
- this.transport.log(info[LEVEL], info.message, info, this._nop);
- }
- callback(null);
- };
- LegacyTransportStream.prototype._writev = function _writev(chunks, callback) {
- for (let i = 0; i < chunks.length; i++) {
- if (this._accept(chunks[i])) {
- this.transport.log(
- chunks[i].chunk[LEVEL],
- chunks[i].chunk.message,
- chunks[i].chunk,
- this._nop
- );
- chunks[i].callback();
- }
- }
- return callback(null);
- };
- LegacyTransportStream.prototype._deprecated = function _deprecated() {
-
- 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'));
- };
- LegacyTransportStream.prototype.close = function close() {
- if (this.transport.close) {
- this.transport.close();
- }
- if (this.transport.__winstonError) {
- this.transport.removeListener('error', this.transport.__winstonError);
- this.transport.__winstonError = null;
- }
- };
|