Skip to content

Commit

Permalink
log: Add standardized logger interface API
Browse files Browse the repository at this point in the history
Add more standardized logger interface functions so that cri-rm
can use the goresctrl logger API.
  • Loading branch information
jukkar committed Sep 27, 2021
1 parent e8c5e4c commit 4d24005
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,30 @@ func (*testlog) Panic(format string, args ...interface{}) {
panic(msg)
}

func (t *testlog) Infof(format string, args ...interface{}) {
t.Info(format, args...)
}

func (t *testlog) Warnf(format string, args ...interface{}) {
t.Warn(format, args...)
}

func (t *testlog) Errorf(format string, args ...interface{}) {
t.Error(format, args...)
}

func (t *testlog) Debugf(format string, args ...interface{}) {
t.Debug(format, args...)
}

func (t *testlog) Fatalf(format string, args ...interface{}) {
t.Fatal(format, args...)
}

func (t *testlog) Panicf(format string, args ...interface{}) {
t.Panic(format, args...)
}

func (*testlog) Block(fn func(string, ...interface{}), prfx string, frmt string, a ...interface{}) {
for _, line := range strings.Split(fmt.Sprintf(frmt, a...), "\n") {
fn("%s%s", prfx, line)
Expand Down
33 changes: 33 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ var levelTag = map[Level]string{

// Logger is the interface for producing log messages for/from a particular source.
type Logger interface {
// Standardized Logger interface functions so that this interface can be
// used from goresctrl library.
Debugf(format string, v ...interface{})
Infof(format string, v ...interface{})
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Panicf(format string, v ...interface{})
Fatalf(format string, v ...interface{})

// Debug formats and emits a debug message.
Debug(format string, args ...interface{})
// Info formats and emits an informational message.
Expand Down Expand Up @@ -452,3 +461,27 @@ func (l logger) block(level Level, prefix, format string, args ...interface{}) {
func loggerError(format string, args ...interface{}) error {
return fmt.Errorf("logger: "+format, args...)
}

func (l logger) Debugf(format string, args ...interface{}) {
l.Debug(format, args...)
}

func (l logger) Infof(format string, args ...interface{}) {
l.Info(format, args...)
}

func (l logger) Warnf(format string, args ...interface{}) {
l.Warn(format, args...)
}

func (l logger) Errorf(format string, args ...interface{}) {
l.Error(format, args...)
}

func (l logger) Panicf(format string, args ...interface{}) {
l.Panic(format, args...)
}

func (l logger) Fatalf(format string, args ...interface{}) {
l.Fatal(format, args...)
}

0 comments on commit 4d24005

Please sign in to comment.