-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
Signed-off-by: Maxim Sukharev <[email protected]>
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? |
We have only one staging_aka_production environment. |
server/service/logger.go
Outdated
|
||
// FluentdFormatter is similar to logrus.JSONFormatter but with log level that are recognized | ||
// by kubernetes fluentd. | ||
type FluentdFormatter struct { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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",
},
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Signed-off-by: Maxim Sukharev <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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
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.