Skip to content

Commit

Permalink
Add a custom log formatter
Browse files Browse the repository at this point in the history
It just keeps the log entry message and appends a newline to it.
This makes them more user-friendly in the terminal.

Before:

    INFO[0000] Log message.

After:

    Log message.

https://jira.mesosphere.com/browse/DCOS_OSS-3746
  • Loading branch information
bamarni committed Jul 9, 2018
1 parent 621b798 commit a8ab14f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/log/formatter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package log

import (
"bytes"
"io/ioutil"
"testing"

"github.com/stretchr/testify/require"

"github.com/sirupsen/logrus"
)

func TestFormat(t *testing.T) {
formatter := &Formatter{}
logger := &logrus.Logger{
Out: ioutil.Discard,
Formatter: formatter,
}

fixtures := []struct {
entry *logrus.Entry
expOut string
}{
{
// simple entry
&logrus.Entry{
Logger: logger,
Message: "DEBUGME",
},
"DEBUGME\n",
},
{
// entry with buffer
&logrus.Entry{
Logger: logger,
Message: "DEBUGMETOO",
Buffer: bytes.NewBuffer(nil),
},
"DEBUGMETOO\n",
},
}

for _, fixture := range fixtures {
out, err := formatter.Format(fixture.entry)
require.NoError(t, err)
require.Equal(t, fixture.expOut, string(out))
}
}

0 comments on commit a8ab14f

Please sign in to comment.