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

Merge pull request #34520 from fnoeding/fixed-raw-splunk-logger

Fixed `raw` mode splunk logger
This commit is contained in:
Vincent Demeester 2017-09-19 10:53:01 +02:00 committed by GitHub
commit 5c57ca17d5
2 changed files with 13 additions and 0 deletions

View file

@ -15,6 +15,7 @@ import (
"net/url"
"os"
"strconv"
"strings"
"sync"
"time"
@ -363,6 +364,11 @@ func (l *splunkLoggerJSON) Log(msg *logger.Message) error {
}
func (l *splunkLoggerRaw) Log(msg *logger.Message) error {
// empty or whitespace-only messages are not accepted by HEC
if strings.TrimSpace(string(msg.Line)) == "" {
return nil
}
message := l.createSplunkMessage(msg)
message.Event = string(append(l.prefix, msg.Line...))

View file

@ -713,12 +713,19 @@ func TestRawFormatWithoutTag(t *testing.T) {
if err := loggerDriver.Log(&logger.Message{Line: []byte("notjson"), Source: "stdout", Timestamp: message2Time}); err != nil {
t.Fatal(err)
}
message3Time := time.Now()
if err := loggerDriver.Log(&logger.Message{Line: []byte(" "), Source: "stdout", Timestamp: message3Time}); err != nil {
t.Fatal(err)
}
err = loggerDriver.Close()
if err != nil {
t.Fatal(err)
}
// message3 would have an empty or whitespace only string in the "event" field
// both of which are not acceptable to HEC
// thus here we must expect 2 messages, not 3
if len(hec.messages) != 2 {
t.Fatal("Expected two messages")
}