Open foobacca opened 7 years ago
Would you mind posting an example of the desired usage and output?
It's structured like JSON but a bit more readable. Plenty of examples in that posted link.
Based on the links, the clearest example I saw was from here:
foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf
You can get something like that with the custom logger:
import pygogo as gogo
kwargs = {'f': True}
extra = {'foo': 'bar, 'a': 14, 'baz': 'hello kitty', 'story': 'bro'}
logfmt = 'foo="%(foo)s" a="%(a)s" baz="%(baz)s" cool_story="%(story)s" "%(message)s"'
fmtr = logging.Formatter(logfmt)
logger = gogo.Gogo('custom', low_formatter=fmtr).get_logger(**kwargs)
logger.debug('%^asdf', extra=extra)
# Prints the following to `stdout`:
foo=bar a=14 baz="hello kitty" cool_story=bro %^asdf
Is that what you are talking about?
Yes, except everything is key value, even the message (message="%^asdf"). And there has to be smart quoting "" for spaces and strings with quotes.
@offero, unfortunately, the link I posted above doesn't match what you just said. They don't display keys for the last two values. Can you please show a complete usage example for what you are looking to achieve? Thanks!
logfmt (second article) is a format meant to be between JSON and normal logs for (human) readability and (machine) parse-ability.
Any chance it could be added to pygogo? I might have a go myself, but thought I'd ask at least.