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

Add support for logfmt #7

Open
foobacca opened this issue Dec 4, 2016 · 6 comments
Open

Add support for logfmt #7

foobacca opened this issue Dec 4, 2016 · 6 comments

Comments

@foobacca
Copy link

foobacca commented Dec 4, 2016

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.

@reubano
Copy link
Owner

reubano commented Feb 10, 2017

Would you mind posting an example of the desired usage and output?

@offero
Copy link

offero commented Nov 6, 2017

It's structured like JSON but a bit more readable. Plenty of examples in that posted link.

@offero
Copy link

offero commented Nov 6, 2017

@reubano
Copy link
Owner

reubano commented Feb 1, 2018

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?

@offero
Copy link

offero commented Feb 1, 2018

Yes, except everything is key value, even the message (message="%^asdf"). And there has to be smart quoting "" for spaces and strings with quotes.

@reubano
Copy link
Owner

reubano commented Feb 1, 2018

@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!

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

No branches or pull requests

3 participants