tools/loglinter/README.md
log-linter checks Go code for logging policy violations.
It runs as a golangci-lint module plugin custom linter named loglinter.
Current checks:
log/slog imports unless allowlistedlog.* calls unless allowlisted*zap.Logger message stringsfmt.Sprintf(...) used as a zap message.With(logging.Component(...)) in the same expressionA repo-root .custom-gcl.yml is included for the custom binary build.
From the repo root:
make golangci-lint-custom
That builds the binary through the Docker-based flow and outputs it to _out/custom-gcl.
Run it directly:
_out/custom-gcl run --config .golangci.yml
.golangci.ymlAdd a custom linter entry like this:
version: "2"
linters:
enable:
- loglinter
settings:
custom:
loglinter:
type: module
description: checks logging conventions
settings:
exclude:
- "**/*_test.go"
- "_out/**"
- "vendor/**"
rules:
slog_imports:
allow:
- "internal/app/machined/pkg/runtime/v1alpha1/platform/vmware/vmware_supported.go"
The repository root is the directory containing the golangci-lint config file.
All rules are enabled by default. An empty settings block applies every rule to every analyzed Go file under the repository root.
Use config mainly to carve out exceptions.
allow is the recommended way to exempt files from a specific rule.exclude is a broader file skip for a rule or for the whole run.include is still supported when you intentionally want to narrow a rule, but the default is repo-wide enforcement.enabled: false explicitly disables a rule.**.A single issue can be ignored with a same-line or immediately preceding comment:
// loglint:ignore stdlib_log_calls compatibility adapter
log.Printf("allowed here")
Multiple rules can be listed as a comma-separated token:
// loglint:ignore stdlib_log_calls,zap_root_component reason
Use all to suppress every rule for the next line or same line.
loglinter is enabled in .golangci.yml, use the custom binary (./custom-gcl) or make golangci-lint-custom; a stock golangci-lint binary will not have the plugin compiled in..With(logging.Component(...)) when that wrapper appears in the same expression as the configured constructor call.