Skip to content

Commit

Permalink
Merge pull request #2651 from getlantern/issue2650
Browse files Browse the repository at this point in the history
Fixed log message length for loggly grouping closes #2650
  • Loading branch information
fffw committed Jun 18, 2015
2 parents 421967c + 9c4c840 commit 8dba727
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/github.com/getlantern/flashlight/logging/logging.go
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/github.com/getlantern/flashlight/logging/logging_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)))
}
}

0 comments on commit 8dba727

Please sign in to comment.