loglint is a Go static analyzer that checks log messages for quality and safety issues. It runs as a golangci-lint plugin or as a standalone analyzer (singlechecker).
| # | Rule | Description |
|---|---|---|
| 1 | lowercase_start | Log messages must start with a lowercase letter (string literals only) |
| 2 | english_only | Log messages must not contain non-ASCII letters (string literals only; emojis ignored) |
| 3 | no_special_chars | Log messages must not contain emojis or non-alnum characters (string literals only) |
| 4 | no_sensitive_data | Looks for sensitive keywords in identifiers in the message expression and in identifiers or string literals in arguments after the message |
log/slogwithInfo/Warn/Error/Debug,*Context, andLoggo.uber.org/zapwithSugaredLogger(Info/Infof/Infow/...) andLogger(Info/Warn/Error/...)log(standard library) withPrint*,Fatal*, andPanic*
The analyzer also recognizes common receiver names like log, logger, l, s, sugar, and zap when deciding how to extract the message argument.
make buildmake plugin./loglint ./...Flags:
-config /path/to/.loglint.yml-fix(apply suggested fixes)
- Build the plugin:
make plugin- Add it to
.golangci.yml:
linters-settings:
custom:
loglint:
path: ./loglint.so
description: "Linter for checking log messages"
original-url: github.com/alchemmist/loglint
linters:
enable:
- loglint- Run:
golangci-lint runIf your golangci-lint version supports analyzer fixes, run it with --fix to apply loglint suggestions.
Supported file names:
.loglint.yml.loglint.yaml.loglint.json
The analyzer searches the current directory and all parent directories. You can also pass -config to point to a specific file.
rules:
lowercase_start: true
english_only: true
no_special_chars: true
no_sensitive_data: true
patterns:
sensitive_keywords:
- password
- secret
- token
- api_key
- private_key{
"rules": {
"lowercase_start": true,
"english_only": true,
"no_special_chars": true,
"no_sensitive_data": true
},
"patterns": {
"sensitive_keywords": ["password", "secret", "token", "api_key", "private_key"]
}
}If sensitive_keywords is empty, the default keyword list is used.
Suggested fixes are provided for:
- lowercase_start: lowercases the first character
- no_special_chars: removes emojis and non-alnum characters (collapses extra spaces)
Apply fixes via -fix in the standalone CLI or via golangci-lint --fix if supported.
- Rules 1-3 only run when the log message is a string literal.
- The sensitive data rule does not scan the literal message text itself. It scans identifiers in the message expression and identifiers or string literals in arguments after the message.
# Run tests
make test
# Run tests with coverage report
make test-cover
# Run vet, formatting checks, golangci-lint, and staticcheck
make check
# Format the codebase (gofmt + gofumpt)
make fmt
# Clean build artifacts and local caches
make cleancmd/ # Standalone CLI entrypoint
pkg/analyzer/ # Analyzer implementation, rules, and config
plugin/ # golangci-lint plugin
testdata/ # Analyzer test fixtures
MIT