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 {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatalln("gelf.UDPWriter is not set!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g GELFMessage) GELFFormat() *gelf.Message {
|
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{
|
return &gelf.Message{
|
||||||
Version: "1.1",
|
Version: "1.1",
|
||||||
Host: g.Host,
|
Host: g.Host,
|
||||||
@ -42,6 +49,6 @@ func (g GELFMessage) GELFFormat() *gelf.Message {
|
|||||||
Full: g.LongMessage,
|
Full: g.LongMessage,
|
||||||
TimeUnix: float64(g.Timestamp.Unix()),
|
TimeUnix: float64(g.Timestamp.Unix()),
|
||||||
Level: int32(g.Level),
|
Level: int32(g.Level),
|
||||||
Extra: g.ExtraFields,
|
Extra: prefixedExtras,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ func New(options ...Option) (*Exporter, error) {
|
|||||||
|
|
||||||
return &Exporter{
|
return &Exporter{
|
||||||
gelfWriter: writer,
|
gelfWriter: writer,
|
||||||
|
appName: cfg.AppName,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user