Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Sep 23, 2024
1 parent 6c11aa6 commit 967a0c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 6 additions & 2 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ type LogArgs struct {
LogLevel string `arg:"-l, --log-level" default:"info" help:"Set the logging level (debug, info, warn, error)"`
}

type Logger struct {
*logrus.Logger
}

// NewLogger returns a new logger with the given log level (info, debug, warn, error)
func NewLogger(logLevel string) *logrus.Logger {
func NewLogger(logLevel string) *Logger {
log := logrus.New()
log.Formatter = new(customFormatter)
switch logLevel {
Expand All @@ -29,7 +33,7 @@ func NewLogger(logLevel string) *logrus.Logger {
log.SetLevel(logrus.InfoLevel)
log.Warnf("Unknown log level '%s', defaulting to info", logLevel)
}
return log
return &Logger{log}
}

type customFormatter struct{}
Expand Down
7 changes: 3 additions & 4 deletions saltutil/saltutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/TheCacophonyProject/go-utils/logging"
"github.com/sirupsen/logrus"
)

const (
Expand All @@ -24,7 +23,7 @@ type Grains struct {
Group string `json:"group,omitempty"`
}

func SetGrains(grains Grains, log *logrus.Logger) error {
func SetGrains(grains Grains, log *logging.Logger) error {
// Setup logger if none is provided
if log == nil {
log = logging.NewLogger("info")
Expand All @@ -48,7 +47,7 @@ func SetGrains(grains Grains, log *logrus.Logger) error {
}

// GetSaltGrains returns the salt grains. Optional to pass a logger, pass nil to use default.
func GetSaltGrains(log *logrus.Logger) (*Grains, error) {
func GetSaltGrains(log *logging.Logger) (*Grains, error) {
// Setup logger if none is provided
if log == nil {
log = logging.NewLogger("info")
Expand Down Expand Up @@ -114,7 +113,7 @@ func GetNodegroupFromFile() (string, error) {
return strings.TrimSpace(string(nodegroup)), nil
}

func GetMinionID(log *logrus.Logger) (string, error) {
func GetMinionID(log *logging.Logger) (string, error) {
// Setup logger if none is provided
if log == nil {
log = logging.NewLogger("info")
Expand Down

0 comments on commit 967a0c3

Please sign in to comment.