Skip to content

Commit

Permalink
added Null Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Jun 8, 2019
1 parent e33e7c6 commit 537d915
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/plugins/logger/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
log "github.com/sirupsen/logrus"
)

// Logrus uses github.com/sirupsen/logrus to log messages
// Logrus uses github.com/sirupsen/logrus to log messages. Implements gornir.Logger Interface
type Logrus struct {
logger *log.Entry
}
Expand All @@ -24,26 +24,33 @@ func NewLogrus(debug bool) *Logrus {
logger.SetOutput(os.Stdout)
return &Logrus{logger: log.NewEntry(logger)}
}

// WithField implements gornir.Logger interface
func (l *Logrus) WithField(field string, value interface{}) gornir.Logger {
return &Logrus{logger: l.logger.WithFields(log.Fields{field: value})}
}

// Info implements gornir.Logger interface
func (l *Logrus) Info(args ...interface{}) {
l.logger.Info(args...)
}

// Debug implements gornir.Logger interface
func (l *Logrus) Debug(args ...interface{}) {
l.logger.Debug(args...)
}

// Error implements gornir.Logger interface
func (l *Logrus) Error(args ...interface{}) {
l.logger.Error(args...)
}

// Warn implements gornir.Logger interface
func (l *Logrus) Warn(args ...interface{}) {
l.logger.Warn(args...)
}

// Fatal implements gornir.Logger interface
func (l *Logrus) Fatal(args ...interface{}) {
l.logger.Fatal(args...)
}
39 changes: 39 additions & 0 deletions pkg/plugins/logger/null.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package logger

import (
"github.com/nornir-automation/gornir/pkg/gornir"
)

// Null is a logger that doesn't do anything. Implements gornir.Logger interface
type Null struct {
}

// NewNull instantiates a new Null logger
func NewNull() *Null {
return &Null{}
}

// WithField implements gornir.Logger interface
func (n *Null) WithField(field string, value interface{}) gornir.Logger {
return n
}

// Info implements gornir.Logger interface
func (n *Null) Info(args ...interface{}) {
}

// Debug implements gornir.Logger interface
func (n *Null) Debug(args ...interface{}) {
}

// Error implements gornir.Logger interface
func (n *Null) Error(args ...interface{}) {
}

// Warn implements gornir.Logger interface
func (n *Null) Warn(args ...interface{}) {
}

// Fatal implements gornir.Logger interface
func (n *Null) Fatal(args ...interface{}) {
}

0 comments on commit 537d915

Please sign in to comment.