Skip to content

Commit

Permalink
Always log file position and combine them
Browse files Browse the repository at this point in the history
File and line are now reported combined withing "pos"
  • Loading branch information
rmohr committed Jan 12, 2017
1 parent 2867700 commit 8228f4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 2 additions & 5 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,8 @@ func (l FilteredLogger) log(skipFrames int, params ...interface{}) error {
logParams := make([]interface{}, 0)

logParams = append(logParams, "component", l.component, "level", logLevelNames[l.currentLogLevel])
if l.currentVerbosityLevel > 1 {
_, fileName, lineNumber, _ := runtime.Caller(skipFrames)
logParams = append(logParams, "filename", filepath.Base(fileName))
logParams = append(logParams, "line", lineNumber)
}
_, fileName, lineNumber, _ := runtime.Caller(skipFrames)
logParams = append(logParams, "pos", fmt.Sprintf("%s:%d", filepath.Base(fileName), lineNumber))
return l.logContext.WithPrefix(logParams...).Log(params...)
}
return nil
Expand Down
12 changes: 7 additions & 5 deletions pkg/logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ func TestObject(t *testing.T) {
assert(t, logEntry[1].(string) == "test", "Component was not logged")
assert(t, logEntry[2].(string) == "level", "Logged line did not have level entry")
assert(t, logEntry[3].(string) == "INFO", "Logged line was not of level INFO")
assert(t, logEntry[4].(string) == "name", "Logged line did not contain object name")
assert(t, logEntry[6].(string) == "kind", "Logged line did not contain object kind")
assert(t, logEntry[8].(string) == "uid", "Logged line did not contain UUID")
assert(t, logEntry[4].(string) == "pos", "Logged line was not pos")
assert(t, logEntry[6].(string) == "name", "Logged line did not contain object name")
assert(t, logEntry[8].(string) == "kind", "Logged line did not contain object kind")
assert(t, logEntry[10].(string) == "uid", "Logged line did not contain UUID")
tearDown()
}

Expand Down Expand Up @@ -317,8 +318,9 @@ func TestMultipleLevels(t *testing.T) {
assert(t, logEntry[1].(string) == "test", "Component was not logged")
assert(t, logEntry[2].(string) == "level", "Logged line did not have level entry")
assert(t, logEntry[3].(string) == "INFO", "Logged line was not of level INFO")
assert(t, logEntry[4].(string) == "msg", "Logged line did not contain message header")
assert(t, logEntry[5].(string) == "test", "Logged line did not contain message")
assert(t, logEntry[4].(string) == "pos", "Logged line was not pos")
assert(t, logEntry[6].(string) == "msg", "Logged line did not contain message header")
assert(t, logEntry[7].(string) == "test", "Logged line did not contain message")
tearDown()
}

Expand Down

0 comments on commit 8228f4d

Please sign in to comment.