detached 74af521

refactor(logging): add TruncateURL helper and fix magic numbers

Extract URL truncation to logging package, replace magic numbers with
named constants for linter compliance.
commit
74af521655e0f6760f6b9053672c33aaa7d580d0
author
brice · · 2026-01-14 08:45 UTC
parent
8d4361b
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +16 -3
M internal/application/usecase/navigate.go +5 -2
@@ -17,6 +17,9 @@ const (
1717 // historyQueueSize is the buffer size for the async history queue.
1818 // If the queue is full, new records are dropped with a warning.
1919 historyQueueSize = 100
20+
21+ // logURLMaxLen is the max length for URLs in log messages.
22+ logURLMaxLen = 60
2023 )
2124
2225 // historyRecord holds data for async history recording.
@@ -137,7 +140,7 @@ func (uc *NavigateUseCase) RecordHistory(ctx context.Context, url string) {
137140 // Non-blocking send to async queue
138141 select {
139142 case uc.historyQueue <- historyRecord{url: url, timestamp: now}:
140- log.Debug().Str("url", url).Msg("history record queued")
143+ log.Debug().Str("url", logging.TruncateURL(url, logURLMaxLen)).Msg("history record queued")
141144 default:
142145 // Queue full - log warning but don't block navigation
143146 log.Warn().Str("url", url).Msg("history queue full, dropping record")
@@ -205,7 +208,7 @@ func (uc *NavigateUseCase) UpdateHistoryTitle(ctx context.Context, url, title st
205208
206209 // Normalize URL to match storage (e.g., github.com/ -> github.com)
207210 url = normalizeURLForHistory(url)
208- log.Debug().Str("url", url).Str("title", title).Msg("updating history title")
211+ log.Debug().Str("url", logging.TruncateURL(url, logURLMaxLen)).Str("title", title).Msg("updating history title")
209212
210213 entry, err := uc.historyRepo.FindByURL(ctx, url)
211214 if err != nil {
@@ -17,6 +17,9 @@ const (
17 // historyQueueSize is the buffer size for the async history queue.17 // historyQueueSize is the buffer size for the async history queue.
18 // If the queue is full, new records are dropped with a warning.18 // If the queue is full, new records are dropped with a warning.
19 historyQueueSize = 10019 historyQueueSize = 100
20+
21+ // logURLMaxLen is the max length for URLs in log messages.
22+ logURLMaxLen = 60
20 )23 )
21 24
22 // historyRecord holds data for async history recording.25 // historyRecord holds data for async history recording.
@@ -137,7 +140,7 @@ func (uc *NavigateUseCase) RecordHistory(ctx context.Context, url string) {
137 // Non-blocking send to async queue140 // Non-blocking send to async queue
138 select {141 select {
139 case uc.historyQueue <- historyRecord{url: url, timestamp: now}:142 case uc.historyQueue <- historyRecord{url: url, timestamp: now}:
140- log.Debug().Str("url", url).Msg("history record queued")143+ log.Debug().Str("url", logging.TruncateURL(url, logURLMaxLen)).Msg("history record queued")
141 default:144 default:
142 // Queue full - log warning but don't block navigation145 // Queue full - log warning but don't block navigation
143 log.Warn().Str("url", url).Msg("history queue full, dropping record")146 log.Warn().Str("url", url).Msg("history queue full, dropping record")
@@ -205,7 +208,7 @@ func (uc *NavigateUseCase) UpdateHistoryTitle(ctx context.Context, url, title st
205 208
206 // Normalize URL to match storage (e.g., github.com/ -> github.com)209 // Normalize URL to match storage (e.g., github.com/ -> github.com)
207 url = normalizeURLForHistory(url)210 url = normalizeURLForHistory(url)
208- log.Debug().Str("url", url).Str("title", title).Msg("updating history title")211+ log.Debug().Str("url", logging.TruncateURL(url, logURLMaxLen)).Str("title", title).Msg("updating history title")
209 212
210 entry, err := uc.historyRepo.FindByURL(ctx, url)213 entry, err := uc.historyRepo.FindByURL(ctx, url)
211 if err != nil {214 if err != nil {
M internal/infrastructure/persistence/sqlite/history_repo.go +3 -1
@@ -14,6 +14,8 @@ import (
1414 "github.com/bnema/dumber/internal/logging"
1515 )
1616
17+const logURLMaxLen = 60
18+
1719 type historyRepo struct {
1820 queries *sqlc.Queries
1921 }
@@ -25,7 +27,7 @@ func NewHistoryRepository(db *sql.DB) repository.HistoryRepository {
2527
2628 func (r *historyRepo) Save(ctx context.Context, entry *entity.HistoryEntry) error {
2729 log := logging.FromContext(ctx)
28- log.Debug().Str("url", entry.URL).Msg("saving history entry")
30+ log.Debug().Str("url", logging.TruncateURL(entry.URL, logURLMaxLen)).Msg("saving history entry")
2931
3032 return r.queries.UpsertHistory(ctx, sqlc.UpsertHistoryParams{
3133 Url: entry.URL,
@@ -14,6 +14,8 @@ import (
14 "github.com/bnema/dumber/internal/logging"14 "github.com/bnema/dumber/internal/logging"
15 )15 )
16 16
17+const logURLMaxLen = 60
18+
17 type historyRepo struct {19 type historyRepo struct {
18 queries *sqlc.Queries20 queries *sqlc.Queries
19 }21 }
@@ -25,7 +27,7 @@ func NewHistoryRepository(db *sql.DB) repository.HistoryRepository {
25 27
26 func (r *historyRepo) Save(ctx context.Context, entry *entity.HistoryEntry) error {28 func (r *historyRepo) Save(ctx context.Context, entry *entity.HistoryEntry) error {
27 log := logging.FromContext(ctx)29 log := logging.FromContext(ctx)
28- log.Debug().Str("url", entry.URL).Msg("saving history entry")30+ log.Debug().Str("url", logging.TruncateURL(entry.URL, logURLMaxLen)).Msg("saving history entry")
29 31
30 return r.queries.UpsertHistory(ctx, sqlc.UpsertHistoryParams{32 return r.queries.UpsertHistory(ctx, sqlc.UpsertHistoryParams{
31 Url: entry.URL,33 Url: entry.URL,
M internal/logging/logger.go +8 -0
@@ -189,3 +189,11 @@ func ParseLevel(level string) zerolog.Level {
189189 return zerolog.InfoLevel
190190 }
191191 }
192+
193+// TruncateURL truncates a URL to maxLen characters for logging.
194+func TruncateURL(url string, maxLen int) string {
195+ if len(url) <= maxLen {
196+ return url
197+ }
198+ return url[:maxLen] + "..."
199+}
@@ -189,3 +189,11 @@ func ParseLevel(level string) zerolog.Level {
189 return zerolog.InfoLevel189 return zerolog.InfoLevel
190 }190 }
191 }191 }
192+
193+// TruncateURL truncates a URL to maxLen characters for logging.
194+func TruncateURL(url string, maxLen int) string {
195+ if len(url) <= maxLen {
196+ return url
197+ }
198+ return url[:maxLen] + "..."
199+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close