Files
teleport/lib/utils/log
rosstimothy a0b67f8d8b Update slog json handler to prefer fmt.Stringer over json marshaling (#40019)
Builds on https://github.com/gravitational/teleport/pull/39974 to
prefer writing a single string instead of a json object to logs. This
more closely follows the behavior of the text formatter which
will output strings. The primary motivation is to ensure that no
secrets or unwanted items of a struct make it into json logs because
it is converting an object differently than the text handler.

There are two other options to avoid this, but both rely on doing
the right thing when adding an attribute, which may be overlooked or
forgotten and ultimately not noticed because only text ouput was
tested with.

1) Call .String() directly on the attribute, but this goes against
 the performance guidance in the slog docs.

2) Wrap the attribute in a logutils.StringerAttr which follows the
 recomendations in the slog docs:

> If you want to avoid eagerly paying the cost of the String call
> without causing the handler to potentially inspect the structure
> of the value, wrap the value in a fmt.Stringer implementation
> that hides its Marshal methods.
2024-04-01 13:50:43 +00:00
..