Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fields padding #6

Merged
merged 1 commit into from Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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