Skip to content

Commit

Permalink
fix(LogCollector): the log level used
Browse files Browse the repository at this point in the history
  • Loading branch information
hristoterezov committed Aug 24, 2023
1 parent c2ab145 commit 1db0885
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/LogCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ function LogCollector(logStorage, options) {
this.maxEntryLength = options && options.maxEntryLength ? options.maxEntryLength : 10000;
// Bind the log method for each level to the corresponding method name
// in order to implement "global log transport" object.
Object.keys(Logger.levels).forEach(
Object.values(Logger.levels).forEach(
function (logLevel) {
var methodName = Logger.levels[logLevel];
this[methodName] = function () {
this[logLevel] = function () {
this._log.apply(this, arguments);
}.bind(this, logLevel);
}.bind(this));
Expand Down Expand Up @@ -141,12 +140,19 @@ logLevel /* timestamp, arg2, arg3, arg4... */) {
var msg = '';
for (var i = 1, len = arguments.length; i < len; i++) {
var arg = arguments[i];
// objects logged on error level are always converted to JSON
if ((this.stringifyObjects || logLevel === Logger.levels.ERROR) &&
typeof arg === 'object') {
arg = this.stringify(arg);

if (this.stringifyObjects && typeof arg === 'object') {
// NOTE: We were trying to stringify all error logs before but because of a bug that we were getting the keys
// of the log levels which are all with upper case and comparing it with the keys which are all lower case we
// were never actually strinfying the error logs. That's why I've removed the check for error logs here.
// NOTE: The non-enumerable properties of the objects wouldn't be included in the string after JSON.strigify.
// For example Error instance will be translated to '{}'. So I think we have to eventually do something better
// for parsing the arguments. But since this option for strigify is part of the public interface and I think
// it could be useful in some cases I will it for now.
msg += this.stringify(arg);
} else {
msg += arg;
}
msg += arg;
if (i !== len - 1) {
msg += ' ';
}
Expand Down

0 comments on commit 1db0885

Please sign in to comment.