sloglint – enforce consistent log/slog code style

sloglint is a Go linter focused on code that uses the standard library’s log/slog package.

Structured logging APIs are flexible, but that flexibility can lead to inconsistent messages, key conventions and calling styles across a codebase. sloglint lets teams encode those preferences as static checks so logging conventions can be enforced automatically during development and continuous integration. It is particularly useful in larger services where multiple contributors might otherwise produce structurally different log records for similar events.

This is free and open source software.

Key Features

  • Can report use of global loggers or restrict the check to the default slog logger.
  • Can require context-aware logging functions, including a mode that considers whether a context is available in the surrounding function.
  • Suggests slog.DiscardHandler where an older discard-handler construction can be simplified.
  • Can require log messages to be static strings or constants instead of dynamically formatted text.
  • Supports lowercased or capitalized message-style policies.
  • Detects calls that mix key-value pairs with slog attributes.
  • Can enforce either key-value arguments or attribute arguments as the preferred style.
  • Can require logging arguments to appear on separate lines.
  • Can require raw string keys to be replaced by constants.
  • Supports allowlists and denylists for structured logging keys.
  • Can enforce snake_case, kebab-case, camelCase or PascalCase key naming.
  • Provides autofixes for selected checks.
  • Can analyse user-defined logging wrappers by configuring function names and argument positions.
  • Integrates with Golangci-lint and can also be used as a standalone analyzer.

Website: github.com/go-simpler/sloglint
Support:
Developer: go-simpler
License: Mozilla Public License 2.0

sloglint is written in Go. Learn Go with our recommended free books and free tutorials.


Related Software

Go Linters
reviveDesigned as a drop-in replacement for golint
golangci-lintFast Go linters runner
gosecSecurity scanner for Go projects
StaticcheckAdvanced Go linter
go-criticOpinionated Go source code linter
VetExamines Go source code and reports suspicious constructs
gofumptStricter gofmt
gofmtFormats Go programs
go-ruleguardAnalysis-based Go linter that runs dynamically loaded rules
forbidigoGo linter for forbidding identifiers
godotKeep source code comments consistent

Read our verdict in the software roundup.


Best Free and Open Source Software Explore our carefully curated directory of recommended free and open source software, covering every major software category.

The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk.

LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more.

Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted