git » debian:golang-blitiri-go-log » commit 00fb4d8

Return error from Logger.Log

author ThinkChaos
2020-05-20 23:45:54 UTC
committer Alberto Bertogli
2020-05-22 00:02:25 UTC
parent 2f2af161c4c79155c1d2af0ec1a872ec306f90b5

Return error from Logger.Log

log.go +5 -4

diff --git a/log.go b/log.go
index 3985c8c..eaf3770 100644
--- a/log.go
+++ b/log.go
@@ -166,9 +166,9 @@ func (l *Logger) V(level Level) bool {
 // should rarely be needed, but it's available to allow the caller to have
 // more complex logic if needed. skip is the number of frames to skip when
 // computing the file name and line number.
-func (l *Logger) Log(level Level, skip int, format string, a ...interface{}) {
+func (l *Logger) Log(level Level, skip int, format string, a ...interface{}) error {
 	if !l.V(level) {
-		return
+		return nil
 	}
 
 	// Message.
@@ -202,8 +202,9 @@ func (l *Logger) Log(level Level, skip int, format string, a ...interface{}) {
 	}
 
 	l.Lock()
-	l.w.Write([]byte(msg))
+	_, err := l.w.Write([]byte(msg))
 	l.Unlock()
+	return err
 }
 
 // Debugf logs information at a Debug level.
@@ -226,7 +227,7 @@ func (l *Logger) Errorf(format string, a ...interface{}) error {
 // Fatalf logs information at a Fatal level, and then exits the program with a
 // non-0 exit code.
 func (l *Logger) Fatalf(format string, a ...interface{}) {
-	l.Log(-2, 1, format, a...)
+	l.Log(Fatal, 1, format, a...)
 	// TODO: Log traceback?
 	os.Exit(1)
 }