https://github.com/shogo82148/logrus-slog-hook
log/slog hook for logrus.
https://github.com/shogo82148/logrus-slog-hook
golang logging logrus
Last synced: over 1 year ago
JSON representation
log/slog hook for logrus.
- Host: GitHub
- URL: https://github.com/shogo82148/logrus-slog-hook
- Owner: shogo82148
- License: mit
- Created: 2023-09-08T05:57:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-10T14:34:01.000Z (almost 3 years ago)
- Last Synced: 2025-03-15T21:17:22.749Z (over 1 year ago)
- Topics: golang, logging, logrus
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logrus-slog-formatter
logrus-slog-formatter is [log/slog](https://pkg.go.dev/log/slog) hook for [logrus](https://github.com/sirupsen/logrus).
## SYNOPSIS
```go
package main
import (
"io"
"log/slog"
"os"
sloghook "github.com/shogo82148/logrus-slog-hook"
"github.com/sirupsen/logrus"
)
func main() {
h := slog.NewTextHandler(os.Stderr, nil)
logrus.AddHook(sloghook.New(h))
// logrus-slog-hook outputs the logs into STDERR.
// I recommend that disable the default output.
logrus.SetFormatter(sloghook.NewFormatter())
logrus.SetOutput(io.Discard)
logrus.WithFields(logrus.Fields{
"name": "joe",
"age": 42,
}).Error("Hello world!")
// Output:
// time=2023-09-10T23:32:41.229+09:00 level=ERROR msg="Hello world!" age=42 name=joe
}
```