Matched-message output now routes through slog: level gating and JSON-handler noise #28

Closed
opened 2026-05-12 09:34:45 +02:00 by heiko · 1 comment
Owner

Found during review of #24.

In internal/scanner/scanner.go the matched-but-not-verbose-not-ReportProcessed branch changed from:

if s.terminal {
    fmt.Printf("\033[1m%s\033[0m\n", line)
} else {
    fmt.Println(line)
}

to:

s.logger.Info(line, s.logArgs(matched, opts.Source)...)

Two side effects worth deciding deliberately:

  1. Level gating. Matched lines used to print unconditionally via fmt.Println. They now go through slog and are suppressed if the configured level is above Info (e.g. a future --quiet flag). If matched messages are "primary output" they should not be level-gated.
  2. JSON / journal output noise. logArgs adds tagged, scan, and (when s.terminal) bold/dim to the record. The text handler filters bold/dim; the JSON handler and journal handler don't filter tagged/scan. For --log-format=json deployments, matched messages now appear as JSON with these fields rather than as a single bold human line. Probably intended, but should be acknowledged.

Suggested actions:

  • Decide whether matched output is a log record or primary stdout; document it.
  • Consider filtering bold/dim out of logArgs entirely when !s.terminal so non-text handlers don't carry them.

Refs: PR #24

Found during review of #24. In `internal/scanner/scanner.go` the matched-but-not-verbose-not-ReportProcessed branch changed from: ```go if s.terminal { fmt.Printf("\033[1m%s\033[0m\n", line) } else { fmt.Println(line) } ``` to: ```go s.logger.Info(line, s.logArgs(matched, opts.Source)...) ``` Two side effects worth deciding deliberately: 1. **Level gating.** Matched lines used to print unconditionally via `fmt.Println`. They now go through slog and are suppressed if the configured level is above Info (e.g. a future `--quiet` flag). If matched messages are "primary output" they should not be level-gated. 2. **JSON / journal output noise.** `logArgs` adds `tagged`, `scan`, and (when `s.terminal`) `bold`/`dim` to the record. The text handler filters `bold`/`dim`; the JSON handler and journal handler don't filter `tagged`/`scan`. For `--log-format=json` deployments, matched messages now appear as JSON with these fields rather than as a single bold human line. Probably intended, but should be acknowledged. Suggested actions: - Decide whether matched output is a log record or primary stdout; document it. - Consider filtering `bold`/`dim` out of `logArgs` entirely when `!s.terminal` so non-text handlers don't carry them. Refs: PR #24
Author
Owner

Fixed in 8a33337. Matched-message output now goes through slog instead of writing directly to stdout, so this finding is resolved.

Fixed in 8a33337. Matched-message output now goes through slog instead of writing directly to stdout, so this finding is resolved.
heiko closed this issue 2026-05-13 14:03:46 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IUS/xr-invoiced#28
No description provided.