Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: winstonjs/winston-transport
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.6.0
Choose a base ref
...
head repository: winstonjs/winston-transport
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.7.0
Choose a head ref
  • 9 commits
  • 7 files changed
  • 3 contributors

Commits on Nov 8, 2023

  1. Bump @babel/traverse from 7.10.3 to 7.23.2 (#180)

    Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.10.3 to 7.23.2.
    - [Release notes](https://github.com/babel/babel/releases)
    - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)
    
    ---
    updated-dependencies:
    - dependency-name: "@babel/traverse"
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 8, 2023
    Copy the full SHA
    7bbaf43 View commit details

Commits on Feb 4, 2024

  1. Bump @types/node from 20.8.6 to 20.11.10 (#206)

    Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.8.6 to 20.11.10.
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)
    
    ---
    updated-dependencies:
    - dependency-name: "@types/node"
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 4, 2024
    Copy the full SHA
    0a134d3 View commit details
  2. Bump eslint from 8.51.0 to 8.56.0 (#199)

    Bumps [eslint](https://github.com/eslint/eslint) from 8.51.0 to 8.56.0.
    - [Release notes](https://github.com/eslint/eslint/releases)
    - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
    - [Commits](eslint/eslint@v8.51.0...v8.56.0)
    
    ---
    updated-dependencies:
    - dependency-name: eslint
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 4, 2024
    Copy the full SHA
    aee4f5f View commit details
  3. Bump actions/setup-node from 3 to 4 (#185)

    Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
    - [Release notes](https://github.com/actions/setup-node/releases)
    - [Commits](actions/setup-node@v3...v4)
    
    ---
    updated-dependencies:
    - dependency-name: actions/setup-node
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 4, 2024
    Copy the full SHA
    5cefa55 View commit details
  4. Bump rimraf from 3.0.2 to 5.0.5 (#181)

    Bumps [rimraf](https://github.com/isaacs/rimraf) from 3.0.2 to 5.0.5.
    - [Changelog](https://github.com/isaacs/rimraf/blob/main/CHANGELOG.md)
    - [Commits](isaacs/rimraf@v3.0.2...v5.0.5)
    
    ---
    updated-dependencies:
    - dependency-name: rimraf
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 4, 2024
    Copy the full SHA
    5c14025 View commit details
  5. Bump deep-equal from 2.2.2 to 2.2.3 (#190)

    Bumps [deep-equal](https://github.com/inspect-js/node-deep-equal) from 2.2.2 to 2.2.3.
    - [Changelog](https://github.com/inspect-js/node-deep-equal/blob/main/CHANGELOG.md)
    - [Commits](inspect-js/node-deep-equal@v2.2.2...v2.2.3)
    
    ---
    updated-dependencies:
    - dependency-name: deep-equal
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 4, 2024
    Copy the full SHA
    5a5a0ca View commit details
  6. Bump actions/checkout from 3 to 4 (#182)

    Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
    - [Release notes](https://github.com/actions/checkout/releases)
    - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
    - [Commits](actions/checkout@v3...v4)
    
    ---
    updated-dependencies:
    - dependency-name: actions/checkout
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 4, 2024
    Copy the full SHA
    66e8fdb View commit details
  7. Resolve circular dependency issues downstream in Winston (#207)

    * Fix circular dependency between transport streams
    
    There is a circular dependency between the `TransportStream` (formerly in `index.js`) and `LegacyTransportStream` (in `legacy.js`). This causes some funky problems when you import the legacy module and later import the main module, as seen in winstonjs/winston#1886. I've resolved the circular issue here by definiting the main implementation of `TransportStream` in a separate module (which `LegacyTransportStream` now depends on) and then doing the work of decorating it with a `.LegacyTransportStream` property in `index.js` (and that's pretty much all the index module does).
    
    * Resolve lint warning while I'm here
    Mr0grog authored Feb 4, 2024
    Copy the full SHA
    377285d View commit details
  8. 4.7.0

    DABH committed Feb 4, 2024
    Copy the full SHA
    f4be5c7 View commit details
Showing with 1,593 additions and 519 deletions.
  1. +2 −2 .github/workflows/ci.yml
  2. +2 −210 index.js
  3. +1 −1 legacy.js
  4. +211 −0 modern.js
  5. +1,374 −303 package-lock.json
  6. +2 −2 package.json
  7. +1 −1 test/index.test.js
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ jobs:
- 18
- 20
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install Dependencies
212 changes: 2 additions & 210 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,215 +1,7 @@
'use strict';

const util = require('util');
const Writable = require('readable-stream/lib/_stream_writable.js');
const { LEVEL } = require('triple-beam');

/**
* Constructor function for the TransportStream. This is the base prototype
* that all `winston >= 3` transports should inherit from.
* @param {Object} options - Options for this TransportStream instance
* @param {String} options.level - Highest level according to RFC5424.
* @param {Boolean} options.handleExceptions - If true, info with
* { exception: true } will be written.
* @param {Function} options.log - Custom log function for simple Transport
* creation
* @param {Function} options.close - Called on "unpipe" from parent.
*/
const TransportStream = module.exports = function TransportStream(options = {}) {
Writable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });

this.format = options.format;
this.level = options.level;
this.handleExceptions = options.handleExceptions;
this.handleRejections = options.handleRejections;
this.silent = options.silent;

if (options.log) this.log = options.log;
if (options.logv) this.logv = options.logv;
if (options.close) this.close = options.close;

// Get the levels from the source we are piped from.
this.once('pipe', logger => {
// Remark (indexzero): this bookkeeping can only support multiple
// Logger parents with the same `levels`. This comes into play in
// the `winston.Container` code in which `container.add` takes
// a fully realized set of options with pre-constructed TransportStreams.
this.levels = logger.levels;
this.parent = logger;
});

// If and/or when the transport is removed from this instance
this.once('unpipe', src => {
// Remark (indexzero): this bookkeeping can only support multiple
// Logger parents with the same `levels`. This comes into play in
// the `winston.Container` code in which `container.add` takes
// a fully realized set of options with pre-constructed TransportStreams.
if (src === this.parent) {
this.parent = null;
if (this.close) {
this.close();
}
}
});
};

/*
* Inherit from Writeable using Node.js built-ins
*/
util.inherits(TransportStream, Writable);

/**
* Writes the info object to our transport instance.
* @param {mixed} info - TODO: add param description.
* @param {mixed} enc - TODO: add param description.
* @param {function} callback - TODO: add param description.
* @returns {undefined}
* @private
*/
TransportStream.prototype._write = function _write(info, enc, callback) {
if (this.silent || (info.exception === true && !this.handleExceptions)) {
return callback(null);
}

// Remark: This has to be handled in the base transport now because we
// cannot conditionally write to our pipe targets as stream. We always
// prefer any explicit level set on the Transport itself falling back to
// any level set on the parent.
const level = this.level || (this.parent && this.parent.level);

if (!level || this.levels[level] >= this.levels[info[LEVEL]]) {
if (info && !this.format) {
return this.log(info, callback);
}

let errState;
let transformed;

// We trap(and re-throw) any errors generated by the user-provided format, but also
// guarantee that the streams callback is invoked so that we can continue flowing.
try {
transformed = this.format.transform(Object.assign({}, info), this.format.options);
} catch (err) {
errState = err;
}

if (errState || !transformed) {
// eslint-disable-next-line callback-return
callback();
if (errState) throw errState;
return;
}

return this.log(transformed, callback);
}
this._writableState.sync = false;
return callback(null);
};

/**
* Writes the batch of info objects (i.e. "object chunks") to our transport
* instance after performing any necessary filtering.
* @param {mixed} chunks - TODO: add params description.
* @param {function} callback - TODO: add params description.
* @returns {mixed} - TODO: add returns description.
* @private
*/
TransportStream.prototype._writev = function _writev(chunks, callback) {
if (this.logv) {
const infos = chunks.filter(this._accept, this);
if (!infos.length) {
return callback(null);
}

// Remark (indexzero): from a performance perspective if Transport
// implementers do choose to implement logv should we make it their
// responsibility to invoke their format?
return this.logv(infos, callback);
}

for (let i = 0; i < chunks.length; i++) {
if (!this._accept(chunks[i])) continue;

if (chunks[i].chunk && !this.format) {
this.log(chunks[i].chunk, chunks[i].callback);
continue;
}

let errState;
let transformed;

// We trap(and re-throw) any errors generated by the user-provided format, but also
// guarantee that the streams callback is invoked so that we can continue flowing.
try {
transformed = this.format.transform(
Object.assign({}, chunks[i].chunk),
this.format.options
);
} catch (err) {
errState = err;
}

if (errState || !transformed) {
// eslint-disable-next-line callback-return
chunks[i].callback();
if (errState) {
// eslint-disable-next-line callback-return
callback(null);
throw errState;
}
} else {
this.log(transformed, chunks[i].callback);
}
}

return callback(null);
};

/**
* Predicate function that returns true if the specfied `info` on the
* WriteReq, `write`, should be passed down into the derived
* TransportStream's I/O via `.log(info, callback)`.
* @param {WriteReq} write - winston@3 Node.js WriteReq for the `info` object
* representing the log message.
* @returns {Boolean} - Value indicating if the `write` should be accepted &
* logged.
*/
TransportStream.prototype._accept = function _accept(write) {
const info = write.chunk;
if (this.silent) {
return false;
}

// We always prefer any explicit level set on the Transport itself
// falling back to any level set on the parent.
const level = this.level || (this.parent && this.parent.level);

// Immediately check the average case: log level filtering.
if (
info.exception === true ||
!level ||
this.levels[level] >= this.levels[info[LEVEL]]
) {
// Ensure the info object is valid based on `{ exception }`:
// 1. { handleExceptions: true }: all `info` objects are valid
// 2. { exception: false }: accepted by all transports.
if (this.handleExceptions || info.exception !== true) {
return true;
}
}

return false;
};

/**
* _nop is short for "No operation"
* @returns {Boolean} Intentionally false.
*/
TransportStream.prototype._nop = function _nop() {
// eslint-disable-next-line no-undefined
return void undefined;
};

// Expose modern transport directly as the export
module.exports = require('./modern');

// Expose legacy stream
module.exports.LegacyTransportStream = require('./legacy');
2 changes: 1 addition & 1 deletion legacy.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

const util = require('util');
const { LEVEL } = require('triple-beam');
const TransportStream = require('./');
const TransportStream = require('./modern');

/**
* Constructor function for the LegacyTransportStream. This is an internal
Loading