From 9c4c8404b1d3f48ebc6df17dc3253e5c1136fd20 Mon Sep 17 00:00:00 2001 From: Myles Horton Date: Wed, 17 Jun 2015 15:06:06 -0700 Subject: [PATCH] Fixed log message length for loggly grouping closes #2650 --- src/github.com/getlantern/flashlight/logging/logging.go | 5 +++++ .../getlantern/flashlight/logging/logging_test.go | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/github.com/getlantern/flashlight/logging/logging.go b/src/github.com/getlantern/flashlight/logging/logging.go index ac400a5dfb..493d19dbc7 100644 --- a/src/github.com/getlantern/flashlight/logging/logging.go +++ b/src/github.com/getlantern/flashlight/logging/logging.go @@ -187,6 +187,11 @@ func (w logglyErrorWriter) Write(b []byte) (int, error) { } message := strings.TrimSpace(fullMessage[lastColonPos+1:]) + // Loggly doesn't group fields with more than 100 characters + if len(message) > 100 { + message = message[0:100] + } + firstColonPos := strings.IndexRune(fullMessage, ':') if firstColonPos == -1 { firstColonPos = 0 diff --git a/src/github.com/getlantern/flashlight/logging/logging_test.go b/src/github.com/getlantern/flashlight/logging/logging_test.go index 143733af05..47bf7fec8b 100644 --- a/src/github.com/getlantern/flashlight/logging/logging_test.go +++ b/src/github.com/getlantern/flashlight/logging/logging_test.go @@ -9,7 +9,7 @@ import ( "github.com/getlantern/go-loggly" "github.com/getlantern/golog" - "github.com/getlantern/testify/assert" + "github.com/stretchr/testify/assert" ) func TestLoggly(t *testing.T) { @@ -62,10 +62,13 @@ func TestLoggly(t *testing.T) { } buf.Reset() - longMsg := "message with: really l" + strings.Repeat("o", 100) + "ng reason" + longPrefix := "message with: really l" + longMsg := longPrefix + strings.Repeat("o", 100) + "ng reason" log.Error(longMsg) if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") { assert.Equal(t, "ERROR test", result["locationInfo"]) - assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) "+longMsg), result["message"]) + + assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) "+longPrefix+"(o+)"), result["message"]) + assert.Equal(t, 100, len(result["message"].(string))) } }