This is a work in progress.
onelog is a general-purpose logging interface heavily inspired by the zerolog API. It is designed to provide a user-friendly API for diverse logging requirements. This package supports a wide range of data types and log levels, creating flexibility for various use cases.
onelog includes adapters for several commonly used loggers, enabling easy integration and compatibility with existing logging methodologies. It reduces the friction associated with logging setup and promotes consistency in logging across different parts of a project or across different projects.
Personally, I plan on using this library in my personal projects Notify and doppler-go, to provide the users of both projects with a unified logging interface without having to force them to use a specific logging library.
go get -u github.com/nikoksr/onelog
package main
import (
"go.uber.org/zap"
"golang.org/x/exp/slog"
"github.com/nikoksr/onelog"
slogadapter "github.com/nikoksr/onelog/adapter/slog"
zapadapter "github.com/nikoksr/onelog/adapter/zap"
)
type superheroTracker struct {
logger onelog.Logger
}
func main() {
// Let's use zap's development logger as our superhero event logger
logger, _ := zap.NewDevelopment()
heroes := &superheroTracker{
logger: zapadapter.NewAdapter(logger),
}
// Now let's log a superhero event
heroes.logger.Info().Msg("Superman spotted in New York!")
// Or perhaps we'd rather use slog for logging our superhero sightings
heroes.logger = slogadapter.NewAdapter(slog.Default())
// And now we can log another sighting
heroes.logger.Info().Msg("Wonder Woman seen flying over Paris!")
}
Contributions of all kinds are very welcome! Feel free to check our open issues. Please also take a look at the contribution guidelines.
Please give a ⭐️ if you like this project! This helps us to get more visibility and helps other people to find this project.