diff --git a/Commands/ListCommand.go b/Commands/ListCommand.go index c36bd6a..585ae4d 100644 --- a/Commands/ListCommand.go +++ b/Commands/ListCommand.go @@ -1,14 +1,13 @@ package Commands import ( - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "lpm-cli/Lotus" ) func NewListCommand() *cli.Command{ - logger := Lotus.CreateLogger("listCommand", logrus.WarnLevel) + logger := Lotus.Logger("listCommand") return &cli.Command{ Name: "list", diff --git a/Commands/PullCommand.go b/Commands/PullCommand.go index 1f028b4..b1c2f8b 100644 --- a/Commands/PullCommand.go +++ b/Commands/PullCommand.go @@ -1,14 +1,13 @@ package Commands import ( - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "lpm-cli/Lotus" ) func NewPullCommand() *cli.Command{ - logger := Lotus.CreateLogger("pullCommand", logrus.WarnLevel) + logger := Lotus.Logger("pullCommand") return &cli.Command { Name: "pull", diff --git a/Commands/PushCommand.go b/Commands/PushCommand.go index 3a778b0..2b2d46b 100644 --- a/Commands/PushCommand.go +++ b/Commands/PushCommand.go @@ -1,14 +1,13 @@ package Commands import ( - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "lpm-cli/Lotus" ) func NewPushCommand() *cli.Command { - logger := Lotus.CreateLogger("pushCommand", logrus.WarnLevel) + logger := Lotus.Logger("pushCommand") return &cli.Command { Name: "push", diff --git a/Commands/SearchCommand.go b/Commands/SearchCommand.go index 78a4763..ba34d20 100644 --- a/Commands/SearchCommand.go +++ b/Commands/SearchCommand.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/urfave/cli/v2" "google.golang.org/grpc" - "github.com/sirupsen/logrus" "lpm-cli/Lotus" proto "lpm-cli/Proto/lpm/go" "time" @@ -13,7 +12,7 @@ import ( func NewSearchCommand() *cli.Command { - logger := Lotus.CreateLogger("searchCommand", logrus.WarnLevel) + logger := Lotus.Logger("searchCommand") return &cli.Command { Name: "search", diff --git a/Lotus/Logging.go b/Lotus/Logging.go index 14040cd..c224802 100644 --- a/Lotus/Logging.go +++ b/Lotus/Logging.go @@ -6,7 +6,7 @@ import ( "os" ) -func CheckIfLogFolderExists(){ +func checkIfLogFolderExists(){ _, dirErr := os.Stat("logs") if dirErr != nil{ log.Fatal(dirErr) @@ -22,7 +22,13 @@ func CheckIfLogFolderExists(){ } -func CreateLogger(loggerName string, logLevel logrus.Level) *logrus.Logger{ +var logger = createLogger(logrus.WarnLevel) + +func Logger(section string) *logrus.Entry { + return logger.WithField("section", section) +} + +func createLogger(logLevel logrus.Level) *logrus.Logger{ var logger = logrus.New() logger.Formatter = new(logrus.TextFormatter) diff --git a/main.go b/main.go index 762faef..10f6ac4 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "github.com/urfave/cli/v2" "lpm-cli/Commands" "lpm-cli/Informations" - "github.com/sirupsen/logrus" "lpm-cli/Lotus" "os" ) @@ -12,7 +11,7 @@ import ( func main() { - logger := Lotus.CreateLogger("mainThread", logrus.InfoLevel) + logger := Lotus.Logger("mainThread") app := &cli.App { Name: "lotus-pm",