fix: message formatting errors in GELF exporter
The library used to transport GELF messages did not prefix extra fields with `_` as was previously assumed and the application name was not passed correctly from configuration to the exporter. Now fixed. Related: goc_marek/salego#693
This commit is contained in:
parent
0f866a0ded
commit
a37354cb18
@ -31,10 +31,17 @@ func Log(writer *gelf.UDPWriter, msg GELFMessage) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
} else {
|
||||
log.Fatalln("gelf.UDPWriter is not set!")
|
||||
}
|
||||
}
|
||||
|
||||
func (g GELFMessage) GELFFormat() *gelf.Message {
|
||||
prefixedExtras := make(map[string]interface{}, len(g.ExtraFields))
|
||||
for k, v := range g.ExtraFields {
|
||||
prefixedExtras["_"+k] = v
|
||||
}
|
||||
|
||||
return &gelf.Message{
|
||||
Version: "1.1",
|
||||
Host: g.Host,
|
||||
@ -42,6 +49,6 @@ func (g GELFMessage) GELFFormat() *gelf.Message {
|
||||
Full: g.LongMessage,
|
||||
TimeUnix: float64(g.Timestamp.Unix()),
|
||||
Level: int32(g.Level),
|
||||
Extra: g.ExtraFields,
|
||||
Extra: prefixedExtras,
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ func New(options ...Option) (*Exporter, error) {
|
||||
|
||||
return &Exporter{
|
||||
gelfWriter: writer,
|
||||
appName: cfg.AppName,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user