1 Star 0 Fork 0

litian/rke

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
log.go 717 Bytes
一键复制 编辑 原始数据 按行查看 历史
package log
import (
"context"
"github.com/sirupsen/logrus"
)
type logKey string
const (
key logKey = "rke-logger"
)
type logger interface {
Infof(msg string, args ...interface{})
Warnf(msg string, args ...interface{})
}
func SetLogger(ctx context.Context, logger logger) context.Context {
return context.WithValue(ctx, key, logger)
}
func getLogger(ctx context.Context) logger {
logger, _ := ctx.Value(key).(logger)
if logger == nil {
return logrus.StandardLogger()
}
return logger
}
func Infof(ctx context.Context, msg string, args ...interface{}) {
getLogger(ctx).Infof(msg, args...)
}
func Warnf(ctx context.Context, msg string, args ...interface{}) {
getLogger(ctx).Warnf(msg, args...)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/rke.git
git@gitee.com:litian33/rke.git
litian33
rke
rke
v0.1.17-rc4

搜索帮助