Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions gelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func New(config Config) *Gelf {
return g
}

func (g *Gelf) Log(message string) {
func (g *Gelf) Log(message string) error {
msgJson := g.ParseJson(message)

err := g.TestForForbiddenValues(msgJson)
if err != nil {
log.Printf("Uh oh! %s", err)
return
return err
}

compressed := g.Compress([]byte(message))
Expand All @@ -81,12 +81,17 @@ func (g *Gelf) Log(message string) {

for i, index := 0, 0; i < length; i, index = i+chunksize, index+1 {
packet := g.CreateChunkedMessage(index, chunkCountInt, id, &compressed)
g.Send(packet.Bytes())
err = g.Send(packet.Bytes())
if err != nil {
return err
}
}

} else {
g.Send(compressed.Bytes())
return g.Send(compressed.Bytes())
}

return nil
}

func (g *Gelf) CreateChunkedMessage(index int, chunkCountInt int, id []byte, compressed *bytes.Buffer) bytes.Buffer {
Expand Down Expand Up @@ -156,17 +161,18 @@ func (g *Gelf) TestForForbiddenValues(gmap map[string]interface{}) error {
return nil
}

func (g *Gelf) Send(b []byte) {
func (g *Gelf) Send(b []byte) error {
var addr = g.Config.GraylogHostname + ":" + strconv.Itoa(g.Config.GraylogPort)
udpAddr, err := net.ResolveUDPAddr("udp", addr)
if err != nil {
log.Printf("Uh oh! %s", err)
return
return err
}
conn, err := net.DialUDP("udp", nil, udpAddr)
if err != nil {
log.Printf("Uh oh! %s", err)
return
return err
}
conn.Write(b)
_, err = conn.Write(b)
return err
}