Skip to content

Commit 7eb6617

Browse files
Align log messages compensating for level text length (#20)
1 parent 326c892 commit 7eb6617

File tree

8 files changed

+14
-10
lines changed

8 files changed

+14
-10
lines changed

Taskfile.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ vars:
88
tasks:
99
default:
1010
desc: List all available tasks
11-
internal: true
1211
silent: true
1312
cmds:
1413
- task --list

docs/img/demo.gif

352 Bytes
Loading

docs/img/keys.gif

-598 Bytes
Loading

docs/img/prefix.gif

949 Bytes
Loading

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ require (
88
)
99

1010
require (
11-
golang.org/x/sys v0.33.0 // indirect
12-
golang.org/x/term v0.32.0 // indirect
11+
golang.org/x/sys v0.34.0 // indirect
12+
golang.org/x/term v0.33.0 // indirect
1313
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go.followtheprocess.codes/snapshot v0.6.0 h1:aq7WIc8hInqdpdrOzntk9lqHwxUqSw3YbgL
44
go.followtheprocess.codes/snapshot v0.6.0/go.mod h1:0hskrLbmTgcv3h1YgVgX0CXiiOKq0UvhM4PewnOZOno=
55
go.followtheprocess.codes/test v0.22.0 h1:erXLdEY/Kj0+gt5rNVtHzbJ+7g9l0JBNuzc7WtcFz00=
66
go.followtheprocess.codes/test v0.22.0/go.mod h1:5xDKZUMZ125YgTPBxaAo2nioaSSk7dkfcTCyzsigWzE=
7-
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
8-
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
9-
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
10-
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
7+
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
8+
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
9+
golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
10+
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
1111
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
1212
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=

log.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"os"
1717
"slices"
1818
"strconv"
19+
"strings"
1920
"sync"
2021
"sync/atomic"
2122
"time"
@@ -163,7 +164,11 @@ func (l *Logger) log(level Level, msg string, kv ...any) {
163164
}
164165

165166
buf.WriteByte(':')
166-
buf.WriteByte(' ')
167+
padding := 2
168+
if level == LevelDebug || level == LevelError {
169+
padding = 1
170+
}
171+
buf.WriteString(strings.Repeat(" ", padding))
167172
buf.WriteString(msg)
168173

169174
if numKVs := len(l.kv) + len(kv); numKVs != 0 {

log_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestWith(t *testing.T) {
167167
got := buf.String()
168168
got = strings.TrimSpace(strings.ReplaceAll(got, fixedTimeString, "[TIME]")) + "\n"
169169

170-
want := "[TIME] INFO: I'm an info message\n[TIME] INFO: I'm also an info message sub=true missing=<MISSING>\n"
170+
want := "[TIME] INFO: I'm an info message\n[TIME] INFO: I'm also an info message sub=true missing=<MISSING>\n"
171171
test.Diff(t, got, want)
172172
}
173173

@@ -244,7 +244,7 @@ func TestContext(t *testing.T) {
244244

245245
got := buf.String()
246246

247-
test.Diff(t, got, "1:34PM INFO: Before\n1:34PM INFO: After\n")
247+
test.Diff(t, got, "1:34PM INFO: Before\n1:34PM INFO: After\n")
248248
})
249249

250250
t.Run("missing", func(t *testing.T) {

0 commit comments

Comments
 (0)