Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
* @param {Function} callback - TODO: add param description.
* @returns {undefined}
*/
log(info, callback) {

Check warning on line 52 in lib/winston/transports/console.js

View workflow job for this annotation

GitHub Actions / Tests (20)

Method 'log' has a complexity of 12. Maximum allowed is 11

Check warning on line 52 in lib/winston/transports/console.js

View workflow job for this annotation

GitHub Actions / Tests (20)

Method 'log' has too many statements (19). Maximum allowed is 15

Check warning on line 52 in lib/winston/transports/console.js

View workflow job for this annotation

GitHub Actions / Tests (18)

Method 'log' has a complexity of 12. Maximum allowed is 11

Check warning on line 52 in lib/winston/transports/console.js

View workflow job for this annotation

GitHub Actions / Tests (18)

Method 'log' has too many statements (19). Maximum allowed is 15

Check warning on line 52 in lib/winston/transports/console.js

View workflow job for this annotation

GitHub Actions / Tests (16)

Method 'log' has a complexity of 12. Maximum allowed is 11

Check warning on line 52 in lib/winston/transports/console.js

View workflow job for this annotation

GitHub Actions / Tests (16)

Method 'log' has too many statements (19). Maximum allowed is 15
setImmediate(() => this.emit('logged', info));
// Emit logged event directly - no need for setImmediate since writes are async
this.emit('logged', info);

// Remark: what if there is no raw...?
if (this.stderrLevels[info[LEVEL]]) {
Expand Down
33 changes: 18 additions & 15 deletions lib/winston/transports/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ module.exports = class Http extends TransportStream {
* @returns {undefined}
*/
log(info, callback) {
// Handle callback immediately since HTTP requests are already async
if (callback) {
return callback();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we return here if there's a call back? We would then exit the function before anything is logged?

}

this._request(info, null, null, (err, res) => {
if (res && res.statusCode !== 200) {
err = new Error(`Invalid HTTP Status Code: ${res.statusCode}`);
Expand All @@ -69,12 +74,6 @@ module.exports = class Http extends TransportStream {
this.emit('logged', info);
}
});

// Remark: (jcrugzz) Fire and forget here so requests dont cause buffering
// and block more requests from happening?
if (callback) {
setImmediate(callback);
}
}

/**
Expand Down Expand Up @@ -192,20 +191,24 @@ module.exports = class Http extends TransportStream {
* @param {string} path - request path
*/
_doBatch(options, callback, auth, path) {
// Handle callback immediately since batching is async
if (callback) {
return callback();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same q here

}

this.batchOptions.push(options);
if (this.batchOptions.length === 1) {
// First message stored, it's time to start the timeout!
const me = this;
this.batchCallback = callback;
this.batchTimeoutID = setTimeout(function () {
// timeout is reached, send all messages to endpoint
me.batchTimeoutID = -1;
me._doBatchRequest(me.batchCallback, auth, path);
// First message stored, start the timeout
this.batchTimeoutID = setTimeout(() => {
this.batchTimeoutID = -1;
this._doBatchRequest(null, auth, path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is null passed rather than callback?

}, this.batchInterval);
}
if (this.batchOptions.length === this.batchCount) {
// max batch count is reached, send all messages to endpoint
this._doBatchRequest(this.batchCallback, auth, path);
// max batch count reached, send immediately
clearTimeout(this.batchTimeoutID);
this.batchTimeoutID = -1;
this._doBatchRequest(null, auth, path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same q here

}
}

Expand Down
Loading
Loading