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

Why doesn't this write json to kafka? #9

Open
rocketraman opened this issue Jan 29, 2017 · 9 comments
Open

Why doesn't this write json to kafka? #9

rocketraman opened this issue Jan 29, 2017 · 9 comments

Comments

@rocketraman
Copy link

I'm not sure why this doesn't write json to kafka? We basically take our nice structured log output, and destructure it.

@gavinmcnair
Copy link

Agree completely. Looking into solutions for this now.

@rocketraman
Copy link
Author

Any updates on this? Thanks!

@gavinmcnair
Copy link

gavinmcnair commented Jun 21, 2018

My solution was ugly

Put it back into JSON.

https://github.com/gavinmcnair/logspout-kafka

@OneCricketeer
Copy link

Could just format the template to do that yourself

KAFKA_TEMPLATE="{\"time\":\"{{.Time}}\",\"container_name\":\"{{.Container.Name}}\",\"source\":\"{{.Source}}\",\"data\":\"{{.Data}}\"}"

Or more simply

KAFKA_TEMPLATE="{\"msg\":\"{{.Data}}\"}"

@rocketraman
Copy link
Author

Could just format the template to do that yourself

This is quite likely to result in invalid JSON output, given that it does no escaping whatsoever of the data fields.

@OneCricketeer
Copy link

Probably a way to escape it. Not too familiar with Go templates.

https://golang.org/pkg/text/template/

@rocketraman
Copy link
Author

Well, yes, I mean, that is the obvious workaround. The point of the issue, however, is why we need to do:

JSON -> destructured -> JSON

when we could just output the original JSON in the first place.

@dylanmei
Copy link
Owner

dylanmei commented Oct 4, 2018

We seem to be struggling with the way Logspout is designed: applying templates to Docker log objects.

Interestingly, the stock raw adapter does have a toJSON helper to aid with extracting values from the object from within the template. https://github.com/gliderlabs/logspout#raw-format

@OneCricketeer
Copy link

If the message is already JSON, then I think you would just do KAFKA_TEMPLATE="{{.Data}}". Otherwise, if you need to get the other fields of the container, source, and time, then you need a workaround or use the raw formatting.

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

4 participants