Skip to content

Commit

Permalink
set log level custom, and added formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Antonette Caldwell <[email protected]>
  • Loading branch information
nebula-aac committed Aug 5, 2023
1 parent b4ce50f commit d804beb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logger

import (
"fmt"
"os"
"time"

Expand All @@ -16,15 +17,26 @@ type Handler interface {
Warn(err error)
Error(err error)

Infof(format string, args ...interface{})
Debugf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Warnf(format string, args ...interface{})

// Kubernetes Controller compliant logger
ControllerLogger() logr.Logger
DatabaseLogger() gormlogger.Interface

SetLevel(level logrus.Level)
}

type Logger struct {
handler *logrus.Entry
}

func (l *Logger) SetLevel(level logrus.Level) {
l.handler.Logger.SetLevel(level)
}

// TerminalFormatter is exported
type TerminalFormatter struct{}

Expand Down Expand Up @@ -80,18 +92,33 @@ func (l *Logger) Error(err error) {
}).Log(logrus.ErrorLevel, err.Error())
}

func (l *Logger) Errorf(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
l.handler.Logger.Error(message)
}

func (l *Logger) Info(description ...interface{}) {
l.handler.Log(logrus.InfoLevel,
description...,
)
}

func (l *Logger) Infof(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
l.handler.Log(logrus.InfoLevel, message)
}

func (l *Logger) Debug(description ...interface{}) {
l.handler.Log(logrus.DebugLevel,
description...,
)
}

func (l *Logger) Debugf(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
l.handler.Log(logrus.DebugLevel, message)
}

func (l *Logger) Warn(err error) {
if err == nil {
return
Expand All @@ -105,3 +132,8 @@ func (l *Logger) Warn(err error) {
"suggested-remediation": errors.GetRemedy(err),
}).Log(logrus.WarnLevel, err.Error())
}

func (l *Logger) Warnf(format string, args ...interface{}) {
message := fmt.Sprintf(format, args...)
l.handler.Log(logrus.WarnLevel, message)
}

0 comments on commit d804beb

Please sign in to comment.