代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/RPC-Turbo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright © 2017 Xiao Zhang <zzxx513@gmail.com>.
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file.
*/
package turbo
import (
"io"
"os"
"path"
"runtime"
"strings"
logger "github.com/sirupsen/logrus"
)
var log *logger.Logger
// ContextHook is a hook to be fired when logging on the logging levels returned from
// `Levels()` on your implementation of the interface. Note that this is not
// fired in a goroutine or a channel with workers, you should handle such
// functionality yourself if your call is non-blocking and you don't wish for
// the logging calls for levels returned from `Levels()` to block.
//
// The original hook interface is:
// type Hook interface {
// Levels() []Level
// Fire(*Entry) error
// }
type ContextHook struct{}
// Levels returns active log levels
func (hook ContextHook) Levels() []logger.Level {
return logger.AllLevels
}
// Fire is for adding file, func and line info to logger.
func (hook ContextHook) Fire(entry *logger.Entry) error {
pc := make([]uintptr, 3, 3)
cnt := runtime.Callers(7, pc)
for i := 0; i < cnt; i++ {
pci := pc[i] - 1
fu := runtime.FuncForPC(pci)
name := fu.Name()
if !strings.Contains(name, "github.com/Sirupsen/logrus") {
file, line := fu.FileLine(pci)
entry.Data["file"] = path.Base(file)
entry.Data["func"] = path.Base(name)
entry.Data["line"] = line
break
}
}
return nil
}
func setupLoggerFile(c *Config) {
logPath := c.configs[turboLogPath]
wd, e := os.Getwd()
if e != nil {
panic(e)
}
if len(strings.TrimSpace(logPath)) == 0 {
logPath = wd
}
if !path.IsAbs(logPath) {
logPath = wd + "/" + logPath
}
logPath = path.Clean(logPath)
err := os.MkdirAll(logPath, 0755)
panicIf(err)
file, err := os.OpenFile(logPath+"/turbo.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
panicIf(err)
logger.SetOutput(file)
}
func initLogger(c *Config) {
if c.Env() == "production" {
setupLoggerFile(c)
// Log as JSON instead of the default ASCII formatter.
logger.SetFormatter(&logger.JSONFormatter{})
logger.SetLevel(logger.InfoLevel)
} else {
logger.SetFormatter(&logger.TextFormatter{})
logger.SetOutput(os.Stderr)
logger.SetLevel(logger.DebugLevel)
logger.AddHook(ContextHook{})
}
log = logger.StandardLogger()
}
// SetOutput sets output at runtime
func SetOutput(out io.Writer) {
log.Out = out
log.Formatter = &logger.TextFormatter{}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。