This distribution provides a very simple and slightly opinionated Go package helpful to create slog.Logger instances. I found myself using the same patterns repeatedly, and decided to lift the code into this independent package. Unless you, somehow, find this convenient, there is probably no reason why you should actually use this 🤷
Retrieve the package with:
go get -u -v go.carloscarnero.stream/go-logger
and then it will be ready to use in your project:
package main
import (
"os"
"go.carloscarnero.stream/go-logger"
)
func main() {
// l will be a pointer to a standard library slog.Logger instance. Note
// that no error handling is included in this example.
l, _ := logger.New(os.Stdout, "TEXT", "INFO", false)
l.Info("Hello, world!")
}
Running the above program will send Hello, world!
to the standard output:
level=INFO msg="Hello, world!"
Note
While the module path is go.carloscarnero.stream/go-logger
, the package
is called logger
. This is not very elegant but results from having to
name the source code repository in that particular way.