Skip to content

Make output format of logger compatible with fluentd #163

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

Merged
merged 2 commits into from
Mar 1, 2018

Conversation

smacker
Copy link
Contributor

@smacker smacker commented Feb 23, 2018

Part of #123

Better make it configurable somehow. For example make a new environmental variable which can be TextFormatter, JsonFormatter, FluentdFormatter. And then additional variables to configure json formatter... But for now it looks like overkill.

@smacker smacker requested a review from bzz February 23, 2018 15:46
@bzz bzz requested a review from dpordomingo February 26, 2018 15:06
@bzz
Copy link
Contributor

bzz commented Feb 26, 2018

Nice! What would be the simplest test plan for this?

Could you please also share it in here, if there is a simple way to verify this new format gets picked up by fluentd in k8s?

@smacker
Copy link
Contributor Author

smacker commented Feb 26, 2018

We have only one staging_aka_production environment.
So the only way to verify - deploy it there and raise some errors/warning (maybe we will need to create custom image with those errors)


// FluentdFormatter is similar to logrus.JSONFormatter but with log level that are recognized
// by kubernetes fluentd.
type FluentdFormatter struct {
Copy link
Contributor

@dpordomingo dpordomingo Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused...
I think we could avoid copy-pasting this bunch of code if we could use FluentdFormatter from joonix/log, as can be found at https://github.com/joonix/log/blob/master/fluentd.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have any policy about it.

@bzz what the party says?

This particular code can be found in 2 repositories:
https://github.com/joonix/log/blob/master/fluentd.go
https://github.com/elafarge/gin-http-logger/blob/master/logrus-formatters/fluentd-formatter.go
And I saw more which are absolutely the same but have different naming. For example:
https://github.com/everflow-io/logrus-gcloud-format/blob/master/formatter.go

and it's copy past of original logrus formatter + 9 lines of simple mapping code (can be written in 3):
https://github.com/sirupsen/logrus/blob/master/json_formatter.go

P.S. When I write Go I try to avoid 1 liners dependency hell as it is in npm, but it's up to project/company.

Copy link
Contributor Author

@smacker smacker Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. My bad. Not 9 additional line. Just changes of 3 lines.

I got confused at first. Actually now it looks like it's possible to archive the same effect using only logrus. But I still need clarification about dependencies for the future @bzz

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk... joonix/FluentdFormatter is what sirupsen/logrus suggests.
(or the fluentd hook that idk if it would suit our necessities)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need fluentd hook if you don't use kubernetes.

Those only 3 lines formatter changes:

	data["time"] = entry.Time.Format(timestampFormat)
	data["message"] = entry.Message
	data["severity"] = entry.Level.String()

So we can just do:

&JSONFormatter{
  	FieldMap: FieldMap{
		 FieldKeyTime: "time",
		 FieldKeyLevel: "severity",
		 FieldKeyMsg: "message",
   },
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only requirements, in case of copy-pasting a code with some modifications, is to keep attribution (copyright) and make sure licenses are compatible.

@smacker was there any particular place where this code comes from?

Using logrus JSONFormatter with 3 lines of configuration sounds even better to me, as will avoid extra hassle with licenses/copyrights in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I took it from some gist, then found out its actually fluend format not GCloud format. So I took name from joonix. And there is no license in files in logrus.

Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dpordomingo
Copy link
Contributor

could you ptal @bzz @carlosms

@dpordomingo dpordomingo removed the request for review from bzz February 28, 2018 17:16
Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smacker I tested the tip of #181 in staging aka production and it worked as expected, so please rebase, squash and merge 🗡️

Copy link
Contributor

@bzz bzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome to me

@smacker smacker merged commit 6aefc4f into src-d:master Mar 1, 2018
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

Successfully merging this pull request may close these issues.

4 participants