Skip to content

Commit

Permalink
fix: fields padding (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed Dec 14, 2022
1 parent c765f87 commit b065845
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions logger.go
Expand Up @@ -95,7 +95,7 @@ func (l *Logger) handleLog(e *Entry) {
l.Writer,
"%s %-*s",
style.Render(fmt.Sprintf("%*s", 1+e.Padding, level)),
l.rightPadding(names),
l.rightPadding(names, e.Padding),
e.Message,
)

Expand All @@ -106,11 +106,11 @@ func (l *Logger) handleLog(e *Entry) {
fmt.Fprintln(l.Writer)
}

func (l *Logger) rightPadding(names []string) int {
func (l *Logger) rightPadding(names []string, padding int) int {
if len(names) == 0 {
return 0
}
return 50 - l.Padding
return 50 - padding
}

// WithFields returns a new entry with `fields` set.
Expand Down
2 changes: 1 addition & 1 deletion pkg_test.go
Expand Up @@ -49,7 +49,7 @@ func TestRootLogOptions(t *testing.T) {
log.WithField("foo", "bar").Info("foo")
log.IncreasePadding()
log.Info("increased")
log.WithoutPadding().Info("without padding")
log.WithoutPadding().WithField("foo", "bar").Info("without padding")
log.Info("increased")
log.ResetPadding()
pet := &Pet{"Tobi", 3}
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestRootLogOptions.golden
Expand Up @@ -7,6 +7,6 @@
 ⨯ warn 1
 • foo foo=bar
 • increased
 • without padding
 • without padding foo=bar
 • increased
 • add pet age=3 name=Tobi

0 comments on commit b065845

Please sign in to comment.