Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

sloglint is a Go linter for enforcing consistent style around the standard-library log/slog package. Enable it in golangci-lint to check logger usage, context-aware calls, message format, argument style, and key naming—and to apply supported fixes automatically.

What sloglint does

sloglint (module version v0.12.0, published April 19, 2026, by go-simpler) analyzes calls to log/slog and can apply the same policies to custom logging wrappers. Its purpose is consistency: teams decide how logging should look, and the linter flags code that deviates.

It does not measure logging performance, reliability, adoption, or defect rates; authoritative project material publishes no such statistics.

Install it through golangci-lint

The recommended setup is to enable the linter in your repository’s golangci-lint configuration:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
linters:
  enable:
    - sloglint

golangci-lint has included sloglint since v1.55.0. The official project also publishes prebuilt binaries on its Releases page for standalone use, but the golangci-lint integration is usually easier to standardize in local development and CI.

Rules you can enforce

Logger and context usage

  • no-global controls use of package-level or default global loggers.
  • context can require context-aware methods such as InfoContext when a context is available.

For example, slog.Info("a user has logged in") may be reported as a global-logger call and, when context enforcement is enabled, as a call that should use InfoContext.

Message text

  • static-msg rejects dynamically built messages when a literal or constant should be used.
  • msg-style standardizes capitalization, such as lowercased or capitalized messages.

This catches code such as slog.Info(fmt.Sprintf("a user with id %d has logged in", 42)) when dynamic messages are disallowed. Structured values should generally be logged as attributes rather than interpolated into the message.

Arguments and attributes

  • no-mixed-args prohibits mixing key-value pairs with slog.Attr values in one call.
  • kv-only requires key-value pairs.
  • attr-only requires attributes.
  • args-on-sep-lines requires arguments to appear on separate lines.

A call that combines "user_id", 42 with slog.String(...) can therefore fail the no-mixed-args rule. Choose one argument form for your codebase and document exceptions for wrappers or generated code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keys

  • no-raw-keys can require constants instead of inline key strings.
  • allowed-keys restricts keys to an allow-list.
  • forbidden-keys blocks names that are ambiguous, sensitive, or deprecated.
  • key-naming-case enforces snake_case, kebab-case, camelCase, or PascalCase.

Key policy is especially useful for logs consumed by dashboards, alerts, and search tools: the same field should not appear under several spellings.

Custom logging functions

custom-funcs describes project-specific logging functions so message, argument, and key checks also apply to wrappers around slog. Add wrappers only after their signatures and argument semantics are stable; otherwise a configuration can create noisy or misleading diagnostics.

Choose a team policy before enabling strict checks

A useful baseline answers these questions explicitly:

  1. Are all package-level loggers prohibited, or only use of the default logger?
  2. Are context-aware methods required everywhere, or only in functions that have a context in scope?
  3. Must messages be static? If so, are they lowercased or capitalized?
  4. Will calls use key-value pairs, slog.Attr, or one consistent form?
  5. Should keys be constants, limited to an allow-list, blocked by a deny-list, and normalized to one naming case?
  6. Which wrapper functions need entries in custom-funcs?

Decide these conventions before turning on every rule. A policy that matches your existing logging API is easier to adopt than a strict configuration that forces broad, unrelated rewrites.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Example configuration shape

golangci-lint exposes the following sloglint controls. Values for naming and lists should reflect your repository’s convention:

linters-settings:
  sloglint:
    no-global: true
    context: "scope"
    static-msg: true
    msg-style: "lowercased"
    no-mixed-args: true
    kv-only: true
    args-on-sep-lines: true
    no-raw-keys: true
    allowed-keys:
      - request_id
      - user_id
    forbidden-keys:
      - password
    key-naming-case: "snake_case"
    custom-funcs:
      - "pkg/logx.Info"

Option names and supported values are version-sensitive. Check the golangci-lint configuration for the version installed by your project before copying a setting, particularly the value used for context and the syntax for custom functions.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Autofix and CI workflow

golangci-lint marks sloglint as supporting autofix for applicable diagnostics. Use that capability on a branch, review the resulting diff, and then run the full test suite: an automated edit can satisfy style while still changing a log call’s readability or behavior.

  1. Pin the golangci-lint version used by developers and CI.
  2. Enable sloglint with a small, agreed baseline.
  3. Run the linter locally and fix or explicitly configure existing violations.
  4. Use the linter’s autofix mode only for diagnostics your team has reviewed.
  5. Make the same configuration a required CI check so new code cannot reintroduce drift.
  6. Expand rules in separate changes, reviewing log volume, field compatibility, and wrapper behavior each time.

How sloglint compares with manual review

Approach Rule coverage Strictness Autofix CI integration Custom wrappers
sloglint in golangci-lint Logger/context calls, messages, arguments, keys, and configured wrappers Adjustable per option Supported for applicable diagnostics Native golangci-lint workflow Yes, through custom-funcs
Manual code review Depends on each reviewer and checklist Inconsistent unless heavily documented No Not automatic Possible, but dependent on reviewer knowledge
Unconfigured slog usage No enforced project-wide style None No No policy gate No systematic coverage

sloglint is therefore most valuable when a team wants repeatable enforcement rather than another logging abstraction. It checks source style; it does not replace decisions about retention, redaction, sampling, handler configuration, or operational observability.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Limitations to plan for

  • Rules govern source conventions, not whether a log event is useful or safe to emit.
  • Overly strict key allow-lists can slow legitimate schema evolution.
  • Requiring context-aware methods is only meaningful when the relevant context is available and correctly propagated.
  • Wrapper functions must be configured deliberately; otherwise direct slog calls may be checked while equivalent wrapper calls are not.
  • Configuration syntax and behavior can change with golangci-lint and sloglint versions, so pin and review upgrades.

Bottom line

Enable sloglint through golangci-lint, agree on context, message, argument, and key conventions, then enforce the configuration in CI. Its adjustable rules and supported autofixes make it a practical way to keep Go log/slog calls uniform, including selected project-specific logging wrappers.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.