feat: replace logrus logger with logf

logf is a minimal logger with no dependencies. this commit should
bring down the binary size.
This commit is contained in:
Karan Sharma 2022-07-01 07:29:14 +05:30
parent 218eb0233a
commit 0f8084b13c
14 changed files with 102 additions and 114 deletions

View file

@ -8,7 +8,7 @@ import (
"github.com/mr-karan/doggo/internal/app"
"github.com/mr-karan/doggo/pkg/utils"
"github.com/sirupsen/logrus"
"github.com/mr-karan/logf"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
@ -67,11 +67,11 @@ func main() {
IdleTimeout: ko.Duration("server.keepalive_timeout") * time.Millisecond,
}
logger.WithFields(logrus.Fields{
logger.WithFields(logf.Fields{
"address": srv.Addr,
}).Info("starting server")
if err := srv.ListenAndServe(); err != nil {
logger.Fatalf("couldn't start server: %v", err)
logger.WithError(err).Fatal("couldn't start server")
}
}

View file

@ -9,7 +9,7 @@ import (
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/providers/posflag"
"github.com/sirupsen/logrus"
"github.com/mr-karan/logf"
flag "github.com/spf13/pflag"
)
@ -41,11 +41,11 @@ func initConfig() {
// Read the config files.
cFiles, _ := f.GetStringSlice("config")
for _, f := range cFiles {
logger.WithFields(logrus.Fields{
logger.WithFields(logf.Fields{
"file": f,
}).Info("reading config")
if err := ko.Load(file.Provider(f), toml.Parser()); err != nil {
logger.Fatalf("error reading config: %v", err)
logger.WithError(err).Fatal("error reading config")
}
}
// Load environment variables and merge into the loaded config.
@ -53,7 +53,7 @@ func initConfig() {
return strings.Replace(strings.ToLower(
strings.TrimPrefix(s, "DOGGO_API_")), "__", ".", -1)
}), nil); err != nil {
logger.Fatalf("error loading env config: %v", err)
logger.WithError(err).Fatal("error loading env config")
}
ko.Load(posflag.Provider(f, ".", ko), nil)