Skip to content

Commit

Permalink
fix: fixed boolean field handling
Browse files Browse the repository at this point in the history
As the GELF format only accepts strings or numbers, we need convert
boolean field to string before sending it to the GELF server
  • Loading branch information
jame-developer committed Mar 6, 2024
1 parent fd0db13 commit de52263
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gelflogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/jame-developer/gelf-logger/pkg/zerologger"
"net"
"os"
"strconv"
"sync"
"time"
)
Expand Down Expand Up @@ -172,7 +173,12 @@ func formatGELFMessage(message string, fields map[string]interface{}, host strin
}

for k, v := range fields {
gelfMsg["_"+k] = v
if boolVal, ok := v.(bool); ok {
gelfMsg["_"+k] = strconv.FormatBool(boolVal)
} else {
gelfMsg["_"+k] = v

}
}

msgBytes, err := json.Marshal(gelfMsg)
Expand Down

0 comments on commit de52263

Please sign in to comment.