mirror of
https://github.com/sundowndev/phoneinfoga.git
synced 2026-11-04 12:04:37 +00:00
refactor: create logs package
This commit is contained in:
1 parent
ca29a16d78
commit
bca9ac0d6c
3 files changed
+44
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package logs
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
config := getConfig()
|
||||
logrus.SetLevel(config.Level)
|
||||
logrus.SetReportCaller(config.ReportCaller)
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
Reference in new issue
Block a user