func withContext(logger seelog.LoggerInterface, context ...string) (contextLogger T) { formatFilter := &ContextFormatFilter{Context: context} contextLogger = &Wrapper{Delegate: logger, Format: formatFilter, M: pkgMutex} // additional stack depth so that we print the calling function correctly // stack depth 0 would print the function in the seelog logger (e.g. seelog.Debug) // stack depth 1 would print the function in the wrapper (e.g. wrapper.Debug) // stack depth 2 prints the function calling the logger (wrapper), which is what we want. logger.SetAdditionalStackDepth(2) return contextLogger }
func init() { var seelogger seelog.LoggerInterface var err error fmt.Fprintln(os.Stderr, "Use default config init Logger") seelogger, err = seelog.LoggerFromConfigAsBytes([]byte(defaultConfig)) if err != nil { log.Panicf("Can't init Logger,error:%s", err) return } else { //确保取得正确的调用堆栈 seelogger.SetAdditionalStackDepth(2) } logger = &SeeLogLogger{seelogger} }