-
Notifications
You must be signed in to change notification settings - Fork 2k
Add LogLevel & LogFormat flags #6520
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3c0aea9
refactor to prepare for struct logs
AlexFenlon 1a2dd82
refactor to solve comments
AlexFenlon 711305c
Merge branch 'main' into chore/flagsgo-refactor-for-struct-logs
AlexFenlon 3cdd96a
Merge remote-tracking branch 'refs/remotes/origin/main' into chore/fl…
AlexFenlon 402891c
fix lint
AlexFenlon 2d594ca
Merge remote-tracking branch 'origin/chore/flagsgo-refactor-for-struc…
AlexFenlon ea033cb
Merge remote-tracking branch 'origin/main' into feat/logformat-flag
AlexFenlon f05bdb9
Add Flags for loglevel and logformat.
AlexFenlon 8c5a5f9
Add tests
AlexFenlon 90feb34
add tests for log format
pdabelf5 7187be0
fix tests
AlexFenlon 63eb0cc
add logformat comments and in schema
AlexFenlon 0956ac4
fix spacing
AlexFenlon 27c6075
remove debug
AlexFenlon a049cf2
move logformat to go near loglevel as they are related - address comment
AlexFenlon 37ceb7f
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/log…
AlexFenlon 23b4e49
update logFormat test case names
AlexFenlon b97840b
add docs
AlexFenlon b2a3a79
change fatal messages to warning, update values comment, add glog as …
AlexFenlon 99219c6
Merge branch 'main' into feat/logformat-flag
AlexFenlon f689e48
Merge branch 'main' into feat/logformat-flag
jjngx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "regexp" | ||
| "testing" | ||
|
|
||
| nic_logger "github.com/nginxinc/kubernetes-ingress/internal/logger" | ||
| nic_glog "github.com/nginxinc/kubernetes-ingress/internal/logger/glog" | ||
| ) | ||
|
|
||
| func TestLogFormats(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| format string | ||
| wantre string | ||
| }{ | ||
| { | ||
| name: "glog format message", | ||
| format: "glog", | ||
| wantre: `^I\d{8}\s\d+:\d+:\d+.\d{6}\s+\d+\s\w+\.go:\d+\]\s.*\s$`, | ||
| }, | ||
| { | ||
| name: "json format message", | ||
| format: "json", | ||
| wantre: `^{"time":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+.*","level":"INFO","msg":".*}`, | ||
| }, | ||
| { | ||
| name: "text format message", | ||
| format: "text", | ||
| wantre: `^time=\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+.*level=\w+\smsg=\w+`, | ||
| }, | ||
| } | ||
| t.Parallel() | ||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| ctx := initLogger(tc.format, nic_glog.LevelInfo, &buf) | ||
| l := nic_logger.LoggerFromContext(ctx) | ||
| l.Log(ctx, nic_glog.LevelInfo, "test") | ||
| got := buf.String() | ||
| re := regexp.MustCompile(tc.wantre) | ||
| if !re.MatchString(got) { | ||
| t.Errorf("\ngot:\n%q\nwant:\n%q", got, tc.wantre) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.