Log non-strings into log file like console.log does #3405
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was inspired by #3398, in which the reporter attaches the log file, which doesn't contain a detailed logging of AggregateError.
Examining the Logger, I found that when logging to file and emiting log events to listeners, the log object is built like this:
However,
Array.join
callstoString
on each arg, which, in the case ofError
args, just returns the name and message of the error, without the stack trace or any additional fields.console.log
on the other hand, usesutil.inspect
on non-string arguments, which returns a more detailed object representation, and also has special handling for Error objects.I fixed this issue by mimicking how
console.log
builds the message.I also made a couple of other minor changes:
\#log
fatal
andnote
always logged, regardless ofthis.logLevel
, but file logging still checked againstthis.logLevel
. I fixed the inconsistency (now file logging also disregardsthis.logLevel
forfatal
andnote
). I didn't know if I should also disregard it for log event emitting? currently left that unchanged.In addition, I added unit tests for Logger.