Skip to content

Commit

Permalink
Merge pull request #6 from lpabon/base
Browse files Browse the repository at this point in the history
Use only the basename to shorten the log output
  • Loading branch information
lpabon committed Jan 18, 2017
2 parents 790c95f + a7ed20d commit 562752a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
15 changes: 2 additions & 13 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"io"
"log"
"os"
"path"
"runtime"
"strings"

"github.com/lpabon/godbc"
)
Expand Down Expand Up @@ -53,18 +53,7 @@ type Logger struct {

func logWithLongFile(l *log.Logger, format string, v ...interface{}) {
_, file, line, _ := runtime.Caller(2)

// Shorten the path.
// From
// /builddir/build/BUILD/heketi-3f4a5b1b6edff87232e8b24533c53b4151ebd9c7/src/github.com/heketi/heketi/apps/glusterfs/volume_entry.go
// to
// src/github.com/heketi/heketi/apps/glusterfs/volume_entry.go
i := strings.Index(file, "/src/")
if i == -1 {
i = 0
}

l.Print(fmt.Sprintf("%v:%v: ", file[i:], line) +
l.Print(fmt.Sprintf("%v:%v: ", path.Base(file), line) +
fmt.Sprintf(format, v...))
}

Expand Down
5 changes: 0 additions & 5 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ func TestLogDebug(t *testing.T) {
tests.Assert(t, strings.Contains(testbuffer.String(), "Hello World"), testbuffer.String())
tests.Assert(t, strings.Contains(testbuffer.String(), "log_test.go"), testbuffer.String())

// [testing] DEBUG 2016/04/28 15:25:08 /src/github.com/heketi/heketi/pkg/utils/log_test.go:66: Hello World
fileinfo := strings.Split(testbuffer.String(), " ")[4]
filename := strings.Split(fileinfo, ":")[0]

// Need to check that it starts with /src/github.com
tests.Assert(t, strings.HasPrefix(filename, "/src/github.com/"))
testbuffer.Reset()

l.SetLevel(LEVEL_INFO)
Expand Down

0 comments on commit 562752a

Please sign in to comment.