41 lines
695 B
Go
41 lines
695 B
Go
package klog
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
func caller(depth int) string {
|
|
_, file, line, _ := runtime.Caller(depth)
|
|
short := file
|
|
for i := len(file) - 1; i > 0; i-- {
|
|
if file[i] == '/' {
|
|
short = file[i+1:]
|
|
break
|
|
}
|
|
}
|
|
return fmt.Sprintf("%s:%d", short, line)
|
|
}
|
|
|
|
func stack() string {
|
|
buf := make([]byte, 1024)
|
|
for {
|
|
n := runtime.Stack(buf, false)
|
|
if n < len(buf) {
|
|
return string(buf[:n])
|
|
}
|
|
buf = make([]byte, 2*len(buf))
|
|
}
|
|
}
|
|
|
|
func getAllOffsprings(l *Logger) []*Logger {
|
|
if l.subs == nil || len(l.subs) == 0 {
|
|
return []*Logger{l}
|
|
}
|
|
loggers := []*Logger{}
|
|
for i := range l.subs {
|
|
loggers = append(loggers, getAllOffsprings(l.subs[i])...)
|
|
}
|
|
return loggers
|
|
}
|