slowg

package
v0.0.0-...-ec0dbc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package slowg defines an Analyzer that checks for inappropriate use of Logger.With() from the log/slog package.

Analyzer slowg

slowg: check for inappropriate use of Logger.With().

The slowg checker looks for calls to Logger.With() from the log/slog package. Logger.With() constructs a new Logger containing the provided attributes. The parent logger is cloned when arguments are supplied, which is a relatively expensive operation which should not be used in hot code path. For example, slowg would report the following call:

log.With("key", val).Info("message")

And suggest to replace it with the following one:

log.Info("message", "key", val)

However, the slowg checker does not prevent the use of With and WithGroup.

wlog := log.With("key", val)             // this is fine
wlog.Info("info")                        // this is also fine
wlog.With("more", "attr").Debug("debug") // this is flagged as inappropriate use

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "slowg",
	Doc:      "check for inappropriate use of Logger.With()",
	URL:      "https://github.com/cilium/linters",
	Requires: []*analysis.Analyzer{inspect.Analyzer},
	Run:      run,
}

Analyzer implements an analysis function that checks for inappropriate use of Logger.With.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL