11 Star 11 Fork 0

Gitee 极速下载/goa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/goadesign/goa
克隆/下载
log.go 977 Bytes
一键复制 编辑 原始数据 按行查看 历史
package middleware
import (
"bytes"
"fmt"
"log"
"strings"
)
type (
// Logger is the logging interface used by the middleware to produce
// log entries.
Logger interface {
// Log creates a log entry using a sequence of alternating keys
// and values.
Log(keyvals ...interface{}) error
}
// adapter is a thin wrapper around the stdlib logger that adapts it to
// the Logger interface.
adapter struct {
*log.Logger
}
)
// NewLogger creates a Logger backed by a stdlib logger.
func NewLogger(l *log.Logger) Logger {
return &adapter{l}
}
func (a *adapter) Log(keyvals ...interface{}) error {
n := (len(keyvals) + 1) / 2
if len(keyvals)%2 != 0 {
keyvals = append(keyvals, "MISSING")
}
var fm bytes.Buffer
vals := make([]interface{}, n)
for i := 0; i < len(keyvals); i += 2 {
k := keyvals[i]
v := keyvals[i+1]
vals[i/2] = v
fm.WriteString(fmt.Sprintf(" %s=%%+v", k))
}
a.Logger.Printf(strings.TrimSpace(fm.String()), vals...)
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/goa.git
git@gitee.com:mirrors/goa.git
mirrors
goa
goa
v2.2.2

搜索帮助