例子
"github.com/astaxie/beego/logs" func main1() { //通用的日志输出 logs.Info("日志输出") //多实例日志 log :=logs.NewLogger() log.Info("asdf") beego.Run() }
通用日志输出调用链:
//1、输出日志 logs.Info("日志输出") //2、logs/log.go 中内置了beeLogger , 我们调用Info()方法内部调用了beeLogger.Info() var beeLogger = NewLogger() func Info(f interface{}, v ...interface{}) { beeLogger.Info(formatLog(f, v...)) }
初始化
config.go -> init() -> parseConfig() -> logs.Reset()
//log初始化 //清空原有的adapter logs.Reset() //循环设置conf中的adapter for adaptor, config := range BConfig.Log.Outputs { err := logs.SetLogger(adaptor, config) if err != nil { fmt.Fprintln(os.Stderr, fmt.Sprintf("%s with the config %q got err:%s", adaptor, config, err.Error())) } } logs.SetLogFuncCall(BConfig.Log.FileLineNum)