Merge pull request #31727 from sascha-andres/31726-le-lion-only

Log payload only [logentries]
This commit is contained in:
Vincent Demeester 2017-08-22 14:59:28 +02:00 committed by GitHub
commit b3b630655d

View file

@ -4,9 +4,11 @@ package logentries
import (
"fmt"
"strconv"
"github.com/bsphere/le_go"
"github.com/docker/docker/daemon/logger"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@ -16,11 +18,13 @@ type logentries struct {
containerName string
writer *le_go.Logger
extra map[string]string
lineOnly bool
}
const (
name = "logentries"
token = "logentries-token"
name = "logentries"
token = "logentries-token"
lineonly = "line-only"
)
func init() {
@ -38,32 +42,44 @@ func init() {
func New(info logger.Info) (logger.Logger, error) {
logrus.WithField("container", info.ContainerID).
WithField("token", info.Config[token]).
WithField("line-only", info.Config[lineonly]).
Debug("logging driver logentries configured")
log, err := le_go.Connect(info.Config[token])
if err != nil {
return nil, err
return nil, errors.Wrap(err, "error connecting to logentries")
}
var lineOnly bool
if lineOnly, err = strconv.ParseBool(info.Config[lineonly]); err != nil {
return nil, errors.Wrap(err, "error parsing lineonly option")
}
return &logentries{
containerID: info.ContainerID,
containerName: info.ContainerName,
writer: log,
lineOnly: lineOnly,
}, nil
}
func (f *logentries) Log(msg *logger.Message) error {
data := map[string]string{
"container_id": f.containerID,
"container_name": f.containerName,
"source": msg.Source,
"log": string(msg.Line),
if !f.lineOnly {
data := map[string]string{
"container_id": f.containerID,
"container_name": f.containerName,
"source": msg.Source,
"log": string(msg.Line),
}
for k, v := range f.extra {
data[k] = v
}
ts := msg.Timestamp
logger.PutMessage(msg)
f.writer.Println(f.tag, ts, data)
} else {
line := msg.Line
logger.PutMessage(msg)
f.writer.Println(line)
}
for k, v := range f.extra {
data[k] = v
}
ts := msg.Timestamp
logger.PutMessage(msg)
f.writer.Println(f.tag, ts, data)
return nil
}