1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #40098 from thaJeztah/bump_gelf

bump Graylog2/go-gelf to 1550ee647df0510058c9d67a45c56f18911d80b8
This commit is contained in:
Kirill Kolyshkin 2019-10-17 11:09:17 -07:00 committed by GitHub
commit 098144291d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 13 deletions

View file

@ -90,7 +90,7 @@ github.com/coreos/go-systemd 39ca1b05acc7ad1220e09f133283
github.com/godbus/dbus 5f6efc7ef2759c81b7ba876593971bfce311eab3 # v4.0.0
# gelf logging driver deps
github.com/Graylog2/go-gelf 4143646226541087117ff2f83334ea48b3201841
github.com/Graylog2/go-gelf 1550ee647df0510058c9d67a45c56f18911d80b8 # v2 branch
# fluent-logger-golang deps
github.com/fluent/fluent-logger-golang 7a6c9dcd7f14c2ed5d8c55c11b894e5455ee311b # v1.4.0

View file

@ -3,6 +3,7 @@ package gelf
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
@ -84,29 +85,35 @@ func (m *Message) UnmarshalJSON(data []byte) error {
m.Extra[k] = v
continue
}
ok := true
switch k {
case "version":
m.Version = v.(string)
m.Version, ok = v.(string)
case "host":
m.Host = v.(string)
m.Host, ok = v.(string)
case "short_message":
m.Short = v.(string)
m.Short, ok = v.(string)
case "full_message":
m.Full = v.(string)
m.Full, ok = v.(string)
case "timestamp":
m.TimeUnix = v.(float64)
m.TimeUnix, ok = v.(float64)
case "level":
m.Level = int32(v.(float64))
var level float64
level, ok = v.(float64)
m.Level = int32(level)
case "facility":
m.Facility = v.(string)
m.Facility, ok = v.(string)
}
if !ok {
return fmt.Errorf("invalid type for field %s", k)
}
}
return nil
}
func (m *Message) toBytes() (messageBytes []byte, err error) {
buf := newBuffer()
defer bufPool.Put(buf)
func (m *Message) toBytes(buf *bytes.Buffer) (messageBytes []byte, err error) {
if err = m.MarshalJSONBuf(buf); err != nil {
return nil, err
}
@ -134,7 +141,7 @@ func constructMessage(p []byte, hostname string, facility string, file string, l
Host: hostname,
Short: string(short),
Full: string(full),
TimeUnix: float64(time.Now().Unix()),
TimeUnix: float64(time.Now().UnixNano()) / float64(time.Second),
Level: 6, // info
Facility: facility,
Extra: map[string]interface{}{

View file

@ -43,7 +43,9 @@ func NewTCPWriter(addr string) (*TCPWriter, error) {
// filled out appropriately. In general, clients will want to use
// Write, rather than WriteMessage.
func (w *TCPWriter) WriteMessage(m *Message) (err error) {
messageBytes, err := m.toBytes()
buf := newBuffer()
defer bufPool.Put(buf)
messageBytes, err := m.toBytes(buf)
if err != nil {
return err
}