https://github.com/trviph/lorekeeper
Lorekeeper is a Go package that handles log rotation.
https://github.com/trviph/lorekeeper
go golang log-rotation logging
Last synced: 8 months ago
JSON representation
Lorekeeper is a Go package that handles log rotation.
- Host: GitHub
- URL: https://github.com/trviph/lorekeeper
- Owner: trviph
- License: unlicense
- Created: 2025-01-07T13:45:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-16T19:13:46.000Z (over 1 year ago)
- Last Synced: 2025-01-16T19:32:33.828Z (over 1 year ago)
- Topics: go, golang, log-rotation, logging
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lorekeeper
[](https://pkg.go.dev/github.com/trviph/lorekeeper) [](https://github.com/trviph/lorekeeper/actions/workflows/ci.yaml) [](https://codecov.io/gh/trviph/lorekeeper)
Lorekeeper is a Go package that manages log rotation. It should work nicely with the Go standard log package.
**Note:** Lorekeeper is not a logging package, it only manages the log files, and should be use with other logging packages such as the standard [log](#with-standard-log-package), [slog](#with-standard-slog-package), or [logrus](#with-logrus).
## Quick Guide
For more detailed information, please refer to the [GoDoc](https://pkg.go.dev/github.com/trviph/lorekeeper).
### With Standard log Package
Package [log](https://pkg.go.dev/log) implements a simple logging package.
```go
package main
import (
"log"
"github.com/trviph/lorekeeper"
)
func main() {
// Init lorekeeper, with the default configurations.
defaultKeeper, err := lorekeeper.NewKeeper()
if err != nil {
panic(err)
}
defer defaultKeeper.Close()
// Using lorekeeper with log
logger := log.New(keeper, "[INFO] ", log.Lmsgprefix|log.LstdFlags)
// Starting using the logger
logger.Printf("that's it!")
}
```
### With Standard slog Package
Package [slog](https://pkg.go.dev/log/slog) provides structured logging, in which log records include a message, a severity level, and various other attributes expressed as key-value pairs.
```go
package main
import (
"log/slog"
"github.com/trviph/lorekeeper"
)
func main() {
// Init lorekeeper, with the default configurations.
defaultKeeper, err := lorekeeper.NewKeeper()
if err != nil {
panic(err)
}
defer defaultKeeper.Close()
// Using lorekeeper with slog
logger := slog.New(slog.NewJSONHandler(keeper, nil))
// Starting using the logger
logger.Info("this is info", "msg", "testing")
logger.Error("this is error", "msg", "testing")
}
```
### With Logrus
[Logrus](https://github.com/sirupsen) is a structured, pluggable logging package for Go.
```go
package main
import (
log "github.com/sirupsen/logrus"
"github.com/trviph/lorekeeper"
)
func main() {
// Init lorekeeper, with the default configurations.
defaultKeeper, err := lorekeeper.NewKeeper()
if err != nil {
panic(err)
}
defer defaultKeeper.Close()
// Using lorekeeper with logrus
logger := log.New()
logger.SetLevel(log.InfoLevel)
logger.SetOutput(defaultKeeper)
// Starting using the logger
logger.Info("this will go into the log file")
logger.Debug("this will not")
}
```