slog-gen

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

README ¶

slog-gen

checks pkg.go.dev goreportcard codecov

📌 About

When using log/slog in a production-grade project, it is useful to write helpers to avoid human error in the keys.

slog.Info("a user has logged in", "user_id", 42)
slog.Info("a user has logged out", "user_ip", 42) // oops :(

Depending on your code style, these can be simple constants (if you prefer key-value arguments)...

const UserId = "user_id"

...or constructors for slog.Attr (if you're a safety/performance advocate).

func UserId(value int) slog.Attr {
    return slog.Int("user_id", value)
}

slog-gen generates such code for you based on a simple config (a single source of truth), which makes it easy to share domain-specific helpers between related (micro)services.

📦 Install

Create and fill in the .slog.yml config based on the example, then add the following directive to any .go file and run go generate ./....

//go:generate go run go-simpler.org/slog-gen --config=.slog.yml

To get started, see the .slog.example.yml file and the example directory.

Documentation ¶

The Go Gopher

There is no documentation for this package.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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