Skip to content

Commit

Permalink
🐛 Prevent empty key or value in SetFieldKey function
Browse files Browse the repository at this point in the history
  • Loading branch information
nkmr-jp committed Oct 27, 2023
1 parent 7fb5dba commit 3d4be87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func SetOmitKeys(key ...Key) {

// SetFieldKey is changes the key of the default field.
func SetFieldKey(key Key, val string) {
if key == "" || val == "" {
return
}
fieldKeys[key] = val
}

Expand Down
2 changes: 2 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func TestSetLevelByString(t *testing.T) {
func TestSetFieldKey(t *testing.T) {
SetFieldKey(FunctionKey, "func")
SetFieldKey(StacktraceKey, "stack_trace")
SetFieldKey(CallerKey, "")
SetFieldKey("", "abc")
assert.Equal(t,
map[Key]string{
FunctionKey: "func",
Expand Down

0 comments on commit 3d4be87

Please sign in to comment.