Skip to content
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

pushLog argument serializer #564

Closed
mxab opened this issue Apr 23, 2024 · 0 comments · Fixed by #580
Closed

pushLog argument serializer #564

mxab opened this issue Apr 23, 2024 · 0 comments · Fixed by #580
Labels
feature Request a new feature

Comments

@mxab
Copy link
Contributor

mxab commented Apr 23, 2024

Description

Currently the args array for the pushLog function maps each arg to a string.

{
...
  message: args
    .map((arg) => {
      try {
        return String(arg);
      } catch (err) {
        return '';
      }
    })
    .join(' '),
}

This works but makes logs ugly as soon as someone write console.log("something happened" , {foo: "bar"}) as it yields something happened [object Object]

Proposed solution

Extend the config with a LogMessageSerializer which is used instead of the hard coded String(arg);.

{
...
  message: args
    .map((arg) => {
      return config.logMessageSerializer.serialize(arg)
    })
    .join(' '),
}

Use current behaviour as a default StringLogMessageSerializer in the config but it could be overwritten with a e.g. JSONLogMessageSerializer that would do something like JSON.stringify(arg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant