You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const line = this.useCustomFormat ? info[MESSAGE] : <some custom serialization of info>
Where useCustomFormat is true when some format has been provided to the winston-loki transport instance and false otherwise.
Notes that winston has a concept of "finalizing" and "non-finalizing" formats: if a format is finalizing - it's updating the value of info[MESSAGE]. If a format is non-finalizing - it's not updating info[MESSAGE]. info[MESSAGE] has some default value even without applying any formats.
There are two problematic scenarios:
Only non-finalizing format(s) has been used on the transport level.
It means that useCustomFormat is true and info[MESSAGE] has default value. This default value doesn't include metadata like level and any changes being done by all non-finalizing formats from both logger and transport levels. And this default value will be sent to Loki.
A finalizing format has been used on the logger level and no format has been used on the transport level.
It means that useCustomFormat is false but info[MESSAGE] has some prepared value. This value will be lost during the serialization of info.
Of course, the correct behavior would be to use info[MESSAGE] if a finalizing format has been applied and try to serialize the info object somehow if there were no finalizing format applied. But there is no way to understand if it has been used or not.
It seems that the only way to avoid unexpected behavior is to remove useCustomFormat, always use info[MESSAGE], and explicitly tell in the documentation that some finalizing format must be used.
In most cases, winston.format.json() is exactly what most users would expect to see - we can recommend using it unless there is an explicit need to use some other finalizing format.
After the discussion, I'm willing to make a PR with a fix.
The text was updated successfully, but these errors were encountered:
As it has been found during the discussion in PR there is a problem with the way how Loki message is getting constructied from the
winston
'sinfo
object:Where
useCustomFormat
istrue
when someformat
has been provided to thewinston-loki
transport instance andfalse
otherwise.Notes that
winston
has a concept of "finalizing" and "non-finalizing" formats: if a format is finalizing - it's updating the value ofinfo[MESSAGE]
. If a format is non-finalizing - it's not updatinginfo[MESSAGE]
.info[MESSAGE]
has some default value even without applying any formats.There are two problematic scenarios:
It means that
useCustomFormat
istrue
andinfo[MESSAGE]
has default value. This default value doesn't include metadata likelevel
and any changes being done by all non-finalizing formats from both logger and transport levels. And this default value will be sent to Loki.It means that
useCustomFormat
isfalse
butinfo[MESSAGE]
has some prepared value. This value will be lost during the serialization ofinfo
.Of course, the correct behavior would be to use
info[MESSAGE]
if a finalizing format has been applied and try to serialize theinfo
object somehow if there were no finalizing format applied. But there is no way to understand if it has been used or not.It seems that the only way to avoid unexpected behavior is to remove
useCustomFormat
, always useinfo[MESSAGE]
, and explicitly tell in the documentation that some finalizing format must be used.In most cases,
winston.format.json()
is exactly what most users would expect to see - we can recommend using it unless there is an explicit need to use some other finalizing format.After the discussion, I'm willing to make a PR with a fix.
The text was updated successfully, but these errors were encountered: