https://github.com/secondtruth/go-logger
📖 Common interface for logging facilities in Go
https://github.com/secondtruth/go-logger
interface interoperability logging
Last synced: 11 months ago
JSON representation
📖 Common interface for logging facilities in Go
- Host: GitHub
- URL: https://github.com/secondtruth/go-logger
- Owner: secondtruth
- License: mit
- Created: 2024-01-10T22:06:39.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-18T23:04:52.000Z (about 2 years ago)
- Last Synced: 2025-03-19T20:48:00.250Z (11 months ago)
- Topics: interface, interoperability, logging
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Go Logger interface with implementations
This library provides a common interface for logging in Go. It also provides an implementation of the interface for [slog](https://pkg.go.dev/log/slog),
which is part of the standard library.
Coming soon in independent repositories: Implementations for two other popular log libraries: [Logrus](https://github.com/sirupsen/logrus)
and [zap](https://github.com/uber-go/zap).
## Why is this interface useful?
When we create libraries in general we shouldn't be logging but at times we do have to log, debug what the library is doing or trace the log.
We cannot implement a library with one log library and expect other applications to use the same log library. Here is where this interface comes in.
It allows others to change the log library at any time without changing the code.
## Installation
To install `go-logger`, use the following command:
go get -u github.com/secondtruth/go-logger
## Quick Start
### Example for [slog](https://pkg.go.dev/log/slog)
```go
package main
import (
"os"
"log/slog"
"github.com/secondtruth/go-logger/logger"
)
func main() {
slogHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
slogLog := slog.New(slogHandler)
log, _ := logger.NewSlogLogger(slogLog)
log.WithFields(logger.Fields{
"foo": "bar",
}).Info("message")
}
```