Go library to enhances the slog package with additional handlers and context helpers.
To install use the following command:
go get github.com/loft-orbital/slogx
Refer to the godoc for the full usage documentation.
package main
import "github.com/loft-orbital/slogx"
func main() {
log := slogx.New(os.Stdout, slogx.JSON, false)
log.Info("Hello world!")
}
package main
import (
"context"
"os"
"github.com/loft-orbital/slogx"
)
func foo(ctx context.Context) {
log := slogx.FromContext(ctx)
log.Info("Hello world!")
}
func main() {
log := slogx.New(os.Stdout, slogx.JSON, false)
ctx := slogx.ContextWithLogger(context.Background(), log)
foo(ctx)
}
package main
import (
"google.golang.org/grpc"
"github.com/loft-orbital/slogx"
)
func main() {
dopts := []grpc.DialOptions {
grpc.WithStreamInterceptor(slogx.StreamClientInterceptor(slogx.Default)),
// ... others gRPC dial options
}
client, err := grpc.NewClient("grpchost:443", dopts...)
if err!=nil {
panic(err)
}
// gRPC service created using this client will have the default slogx logger
// available in each stream's context.
}
Please refer to the CONTRIBUTING.md file for information on how to contribute to this project.