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 a flag for including only certain fields #15

Merged
merged 5 commits into from
Jun 18, 2021

Conversation

jalvz
Copy link

@jalvz jalvz commented May 26, 2021

NOTE: this does not affect fields that are part of the title (timestamp, message, etc); I don't think it would be convenient for users to have to explicitly type those.

@trentm
Copy link
Owner

trentm commented Jun 4, 2021

@jalvz Were you intending to start PRs for the three issues? Or did you want to go through them one at a time to minimize merge conflicts? Or if you don't have time to work through and finish PRs, that's totally cool tool.

"ecslog --include-fields ...all the title fields...",
[]string{"ecslog", "-i", "foo", "./testdata/exclude-fields.log"},
0,
regexp.MustCompile(`^\[2021-01-19T22:51:12.142Z\] INFO: hi\n foo: "bar"\n spam: \n$`),
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't the spam: ... line be complete gone here?

Copy link
Author

Choose a reason for hiding this comment

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

yes it, fixed

@trentm
Copy link
Owner

trentm commented Jun 4, 2021

NOTE: this does not affect fields that are part of the title (timestamp, message, etc); I don't think it would be convenient for users to have to explicitly type those.

I'm slightly hesitant to have "-i" fields not apply to the "title" line fields, mainly because the title line is underspecified. What is included in the title line by default may change in future versions and could also differ between formats.

However, I think I agree with you that it'll be useful as you have it.

(Aside: It also makes me want to have a "oneline" format that puts all the extra (non-title line) fields on the same line. Something like:

$ cat some.log | ecslog -i foo,bar
[2021-02-11T06:24:53.251Z]  WARN (myapi on purple.local): something went wrong
    foo: 1
    bar: 2
...
$ cat some.log | ecslog -i foo,bar -f oneline
[2021-02-11T06:24:53.251Z]  WARN (myapi on purple.local): something went wrong (foo:1 bar:2)
...

This is a case where I think -i and a more compact title line could really be nice.)

Anyway, that is a long way to say that I think your call to have -i not count for title line fields is a good call.

internal/ecslog/ecslog_test.go Show resolved Hide resolved
internal/ecslog/ecslog_test.go Outdated Show resolved Hide resolved
"only log",
"no", "", "default", "", "", []string{"log"},
`{"log.level":"info","@timestamp":"2021-01-19T22:51:12.142Z","ecs":{"version":"1.5.0"},"message":"hi","log.origin":{"foo":"bar",file.name":"main.go","file.line":"42"}}`,
"{\"log.level\":\"info\",\"@timestamp\":\"2021-01-19T22:51:12.142Z\",\"ecs\":{\"version\":\"1.5.0\"},\"message\":\"hi\",\"log.origin\":{\"foo\":\"bar\",file.name\":\"main.go\",\"file.line\":\"42\"}}\n",
Copy link
Owner

Choose a reason for hiding this comment

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

Why doesn't this one render?

Copy link
Author

Choose a reason for hiding this comment

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

it should, was missing a ', fixed now

@jalvz
Copy link
Author

jalvz commented Jun 8, 2021

My intention was to do one at a time as time permits, yes. Thanks for the review, I'll have a closer look shortly!

cmd/ecslog/main_test.go Outdated Show resolved Hide resolved
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.

2 participants