-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logging): add logging solution to cli package
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
- Loading branch information
Showing
5 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package log | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Logger is an interface the defines logging methods. | ||
type Logger interface { | ||
Errorf(string, ...interface{}) | ||
Infof(string, ...interface{}) | ||
Warnf(string, ...interface{}) | ||
Debugf(string, ...interface{}) | ||
Fatalf(string, ...interface{}) | ||
} | ||
|
||
type standardLogger struct { | ||
logger *logrus.Logger | ||
} | ||
|
||
// NewLogger returns a new Logger. | ||
func NewLogger(out io.Writer, level string) (Logger, error) { | ||
lvl, err := logrus.ParseLevel(level) | ||
if err != nil { | ||
return nil, err | ||
} | ||
slogr := &standardLogger{ | ||
logger: &logrus.Logger{ | ||
Out: out, | ||
Formatter: new(logrus.TextFormatter), | ||
Hooks: make(logrus.LevelHooks), | ||
Level: lvl, | ||
}, | ||
} | ||
|
||
return slogr, nil | ||
} | ||
|
||
func (l *standardLogger) Errorf(format string, args ...interface{}) { | ||
l.logger.Logf(logrus.ErrorLevel, format, args...) | ||
} | ||
|
||
func (l *standardLogger) Infof(format string, args ...interface{}) { | ||
l.logger.Logf(logrus.InfoLevel, format, args...) | ||
} | ||
|
||
func (l *standardLogger) Warnf(format string, args ...interface{}) { | ||
l.logger.Logf(logrus.WarnLevel, format, args...) | ||
} | ||
|
||
func (l *standardLogger) Debugf(format string, args ...interface{}) { | ||
l.logger.Logf(logrus.DebugLevel, format, args...) | ||
} | ||
|
||
func (l *standardLogger) Fatalf(format string, args ...interface{}) { | ||
l.logger.Logf(logrus.FatalLevel, format, args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters