我正在尝试围绕logrus. 为此,我定义了以下内容
package util
import "github.com/sirupsen/logrus"
type LoggerFields = logrus.Fields
type Logger interface {
Printf(format string, v ...interface{})
Print(v ...interface{})
WithFields(fields LoggerFields) Logger
}
现在在一个单独的方法中,我有以下
func SetupLogger() util.Logger {
l := logrus.WithFields(logrus.Fields{"app": "myapp"})
return l
}
但是我收到以下编译错误
cannot use l (variable of type *logrus.Entry) as util.Logger value in return statement: wrong type for method WithFields (have func(fields github.com/sirupsen/logrus.Fields) *github.com/sirupsen/logrus.Entry, want func(fields github.com/sirupsen/logrus.Fields) testconcepts/util.Logger)
从错误中可以看出,它withFields是引发错误的方法,特别是返回类型。但是*github.com/sirupsen/logrus.Entry接口中的所有方法testconcepts/util.Logger
我不确定它为什么会抛出这个编译错误。