Skip to content

Pino in the browser prints the log bindings weirdly #1556

@segevfiner

Description

@segevfiner

When using pino in the browser multiple child log bindings are just printed one after the other rather than coalesced into a single object: e.g.

logger.child({ foo: 'foo'}).child({ bar: 'bar'}).info("Hello, %s!", "World");

Prints:

{ foo: 'foo'}   { bar: 'bar' }   Hello, World!

Which is kinda weird, as in node you just get a single object.

Ideas

I think what would be helpful here are a few new features:

  • The ability for write to receive the merged and serialized bindings but the message and args unformatted so they can be passed as is to the underlying console methods, keeping their special handling in the Browser devtools. Like a variation of asObject or an additional flag on top of it. – Add asObjectBindingsOnly, allowing write to receive only the bindings as object #2051
  • The ability to get the original log method in write, so you can still forward to the correct console method, while manipulating the way the message with args is written. Which can be used with the above to custom format a log message before being passed to the console method.
  • [ ] Alternatively, an option to get a callback that will get the merged bindings object and args, which will be used to build the arguments for write instead of asObject? Like a different variation of a formatter, that receives the args that write would receive if we do 1 instead, where we won't need to add a way to get the original console method in write or have the user do that to customize formatting in this case.
  • The ability to make pino filter the console messages using the logger level and not only transmit.
  • The ability to get the formatted object in transmit.send, when you want to send it upstream to a logging system rather than echoing it to a server side pino instead.

@mcollina What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions