Skip to content

Commit

Permalink
docs: add README
Browse files Browse the repository at this point in the history
Signed-off-by: TJ Hoplock <[email protected]>
  • Loading branch information
tjhop committed Nov 20, 2024
1 parent c8ae2b1 commit 9bebb3c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Go slog-gokit Adapter

This library provides a custom slog.Handler that wraps a go-kit Logger, so that loggers created via `slog.New()` chain their log calls to the internal go-kit Logger.

## Install

```bash
go get github.com/tjhop/slog-gokit
```

## Example

```go
package main

import (
"log/slog"
"os"

"github.com/go-kit/log"
slgk "github.com/tjhop/slog-gokit"
)

func main() {
// Take an existing go-kit/log Logger:
gklogger := log.NewLogfmtLogger(os.Stderr)

// Create an slog Logger that chains log calls to the go-kit/log Logger:
slogger := slog.New(slgk.NewGoKitHandler(gklogger, nil))
slogger.WithGroup("example_group").With("foo", "bar").Info("hello world")

// The slog Logger produced logs at slog.LevelInfo by default.
// Optionally create an slog.Leveler to dynamically adjust the level of
// the slog Logger.
lvl := &slog.LevelVar{}
lvl.Set(slog.LevelDebug)
slogger = slog.New(slgk.NewGoKitHandler(gklogger, lvl))
slogger.WithGroup("example_group").With("foo", "bar").Info("hello world")
}
```

0 comments on commit 9bebb3c

Please sign in to comment.