Browse Source

修改Error接口

yjp 3 years ago
parent
commit
7febb3139b
2 changed files with 5 additions and 2 deletions
  1. 3 1
      fslog_instance.go
  2. 2 1
      fslog_instance_test.go

+ 3 - 1
fslog_instance.go

@@ -1,6 +1,7 @@
 package fslog
 
 import (
+	"fmt"
 	"go.uber.org/zap"
 	"go.uber.org/zap/zapcore"
 	"os"
@@ -71,9 +72,10 @@ func Info(serviceName string, funcName string, callName string, message string)
 	logger.Info(message, callerFields...)
 }
 
-func Error(serviceName string, funcName string, callName string, message string) {
+func Error(serviceName string, funcName string, callName string, err error) {
 	lazyInitialize()
 	callerFields := getCallerInfoForLog(serviceName, funcName, callName)
+	message:= fmt.Sprintf("\n%+v\n", err)
 	logger.Error(message, callerFields...)
 }
 

+ 2 - 1
fslog_instance_test.go

@@ -1,13 +1,14 @@
 package fslog
 
 import (
+	"github.com/pkg/errors"
 	"testing"
 )
 
 func TestFSLogInstanceToConsole(t *testing.T) {
 	LoggerLever = LoggerLevelDebug
 
-	Error("demo", "TestFSLogInstanceToConsole", "test", "error test")
+	Error("demo", "TestFSLogInstanceToConsole", "test", errors.New("error test"))
 	Debug("demo", "TestFSLogInstanceToConsole", "test", "debug test")
 	Info("demo", "TestFSLogInstanceToConsole", "test", "info test")
 	Warn("demo", "TestFSLogInstanceToConsole", "test", "warning test")