-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ALWAYS send the ORIGINAL, unmutated info object to each registered logger transport #1933
Comments
More InformationSo thinking that const SplatFormat: Format = format((info: TransformableInfo) => {
// @ts-ignore
const { [LEVEL]: symLevel, [SPLAT]: symSplat } = info;
const symSplatCopy = (<Array<Object>>symSplat).map(o => o);
const transformedInfo = <TransformableInfo>format.splat().transform(info);
// @ts-ignore
console.log("[SplatFormat]: Post-splat() - transformedInfo[Symbol(splat)] - ", transformedInfo[SPLAT]);
// @ts-ignore
info = <TransformableInfo>{
...transformedInfo,
// @ts-ignore
[SPLAT]: symSplatCopy,
}
console.log("[SplatFormat]: Post-splat() - transformedInfo - ", transformedInfo);
console.log("[SplatFormat]: Mutated info - ", info);
return info;
})(); The idea was to get the splatted message, but "mutate" the However, once the second transport got the
|
Please tell us about your environment:
winston
version? 3.3.3winston@2
winston@3
node -v
outputs: N/AWhat is the problem?
I realize that in the README for this repository, the project points out that Winston is a mutating logger. However, what is really unexpected is that Winston sends mutated instances of a TransformableInfo object into transports.
What do you expect to happen instead?
I expect that each transport would receive an unmutated (i.e. original) version of the
TransformableInfo
object. In this way, for a single logger instance, each transport could "mutate" the object as required for that particular transport. However, that is not what's happening.Other information
I thought I'd share with you some output I generated as Winston passed along the
info
object through some of my formatters for formatting transport output....For each transport, the order of formatters was kept the same. I ensured that each formatter which I created does not mutate the
info
object passed into it, but returns a new, "transformed"info
object. Here's my logger definition:So, looking at the below output, every line that starts with
==> Default * Format: pre-formatting: ``info``:
, I expect the followinginfo
object definition to be exactly the same for each transport. But you will see that it is not. For example, the very first log entry starts with the Structured Log transport. You can see that, pre-formatting, there's acorrelationId
property field on theinfo
object. However, once we get to the second transport for the unstructured log file, theinfo
object doesn't even have acorrelationId
property at this point! Where did it go? After analyzing the formatters, it seems the key difference is theinfo[Symbol(splat)]
property's value between the two transports. It seems as ifformat.splat
is mutating the originalinfo
object's value for that property, and subsequent transports use the mutated value, losing log data along the way. In addition, something is stripping off the extra metadata between transports. At the end of the first transport, there arecorrelationId
anddeploymentTargetId
properties on theinfo
object, but they don't appear by the time the next transport gets it. But again, had theinfo[Symbol(splat)]
property value not change between transports, that would be a non-issue. So again, it seems likeformat.splat
is the culprit here, BUT, Winston SHOULD NOT be passing a mutatedinfo
object between transports.Should I also file a bug on the
logform
project?The text was updated successfully, but these errors were encountered: