package gelfexporter import ( "fmt" "log" "time" "git.ma-al.com/maal-libraries/observer/pkg/syslog" "gopkg.in/Graylog2/go-gelf.v2/gelf" ) type GELFMessage struct { // Name of the application Host string `json:"host"` // Short, descriptive message ShortMessage string `json:"short_message"` // Optional long message. LongMessage string `json:"long_message,omitempty"` // Timestamp in Unix Timestamp time.Time `json:"timestamp"` // Severity level matching Syslog standard. Level syslog.SyslogLevel `json:"level"` // All additional field names must start with an underline. ExtraFields map[string]interface{} `json:"extrafields,omitempty"` } func Log(writer *gelf.UDPWriter, msg GELFMessage) { if writer != nil { err := writer.WriteMessage(msg.GELFFormat()) if err != nil { log.Println(err) } fmt.Printf("msg: %v sent\n", msg) } } func (g GELFMessage) GELFFormat() *gelf.Message { return &gelf.Message{ Version: "1.1", Host: g.Host, Short: g.ShortMessage, Full: g.LongMessage, TimeUnix: float64(g.Timestamp.Unix()), Level: int32(g.Level), Extra: g.ExtraFields, } }