Updated logging

This commit is contained in:
netbenix 2021-11-06 21:20:49 +01:00
parent ff9e4b3e3a
commit 4859b622a5
6 changed files with 13 additions and 12 deletions

View file

@ -1,14 +1,13 @@
package Commands package Commands
import ( import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"lpm-cli/Lotus" "lpm-cli/Lotus"
) )
func NewListCommand() *cli.Command{ func NewListCommand() *cli.Command{
logger := Lotus.CreateLogger("listCommand", logrus.WarnLevel) logger := Lotus.Logger("listCommand")
return &cli.Command{ return &cli.Command{
Name: "list", Name: "list",

View file

@ -1,14 +1,13 @@
package Commands package Commands
import ( import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"lpm-cli/Lotus" "lpm-cli/Lotus"
) )
func NewPullCommand() *cli.Command{ func NewPullCommand() *cli.Command{
logger := Lotus.CreateLogger("pullCommand", logrus.WarnLevel) logger := Lotus.Logger("pullCommand")
return &cli.Command { return &cli.Command {
Name: "pull", Name: "pull",

View file

@ -1,14 +1,13 @@
package Commands package Commands
import ( import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"lpm-cli/Lotus" "lpm-cli/Lotus"
) )
func NewPushCommand() *cli.Command { func NewPushCommand() *cli.Command {
logger := Lotus.CreateLogger("pushCommand", logrus.WarnLevel) logger := Lotus.Logger("pushCommand")
return &cli.Command { return &cli.Command {
Name: "push", Name: "push",

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"google.golang.org/grpc" "google.golang.org/grpc"
"github.com/sirupsen/logrus"
"lpm-cli/Lotus" "lpm-cli/Lotus"
proto "lpm-cli/Proto/lpm/go" proto "lpm-cli/Proto/lpm/go"
"time" "time"
@ -13,7 +12,7 @@ import (
func NewSearchCommand() *cli.Command { func NewSearchCommand() *cli.Command {
logger := Lotus.CreateLogger("searchCommand", logrus.WarnLevel) logger := Lotus.Logger("searchCommand")
return &cli.Command { return &cli.Command {
Name: "search", Name: "search",

View file

@ -6,7 +6,7 @@ import (
"os" "os"
) )
func CheckIfLogFolderExists(){ func checkIfLogFolderExists(){
_, dirErr := os.Stat("logs") _, dirErr := os.Stat("logs")
if dirErr != nil{ if dirErr != nil{
log.Fatal(dirErr) 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() var logger = logrus.New()
logger.Formatter = new(logrus.TextFormatter) logger.Formatter = new(logrus.TextFormatter)

View file

@ -4,7 +4,6 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"lpm-cli/Commands" "lpm-cli/Commands"
"lpm-cli/Informations" "lpm-cli/Informations"
"github.com/sirupsen/logrus"
"lpm-cli/Lotus" "lpm-cli/Lotus"
"os" "os"
) )
@ -12,7 +11,7 @@ import (
func main() { func main() {
logger := Lotus.CreateLogger("mainThread", logrus.InfoLevel) logger := Lotus.Logger("mainThread")
app := &cli.App { app := &cli.App {
Name: "lotus-pm", Name: "lotus-pm",