refactor: create logs package

This commit is contained in:
sundowndev committed 2022-09-16 12:43:40 +04:00
1 parent ca29a16d78
commit bca9ac0d6c
3 files changed
+44

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
package logs
import (
"github.com/sirupsen/logrus"
"github.com/sundowndev/phoneinfoga/v2/build"
)
type Config struct {
Level logrus.Level
ReportCaller bool
}
func getConfig() Config {
config := Config{
Level: logrus.WarnLevel,
ReportCaller: false,
}
if !build.IsRelease() {
config.Level = logrus.DebugLevel
}
return config
}
+11
View File
@@ -0,0 +1,11 @@
package logs
import (
"github.com/sirupsen/logrus"
)
func Init() {
config := getConfig()
logrus.SetLevel(config.Level)
logrus.SetReportCaller(config.ReportCaller)
}
+9
View File
@@ -1,9 +1,18 @@
package main
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/sundowndev/phoneinfoga/v2/build"
"github.com/sundowndev/phoneinfoga/v2/cmd"
"github.com/sundowndev/phoneinfoga/v2/logs"
)
func main() {
logs.Init()
logrus.WithFields(logrus.Fields{
"isRelease": fmt.Sprintf("%t", build.IsRelease()),
"version": build.String(),
}).Debug("Build info")
cmd.Execute()
}