mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
27 lines
427 B
Go
27 lines
427 B
Go
package log
|
|
|
|
import (
|
|
"io"
|
|
"time"
|
|
|
|
glog "gvisor.dev/gvisor/pkg/log"
|
|
)
|
|
|
|
func init() {
|
|
EnableStackLog(true)
|
|
}
|
|
|
|
func EnableStackLog(v bool) {
|
|
if v {
|
|
glog.SetTarget(&emitter{}) // built-in logger
|
|
} else {
|
|
glog.SetTarget(&glog.Writer{Next: io.Discard})
|
|
}
|
|
}
|
|
|
|
type emitter struct{}
|
|
|
|
func (emitter) Emit(_ int, level glog.Level, _ time.Time, format string, args ...any) {
|
|
logf(Level(level)+2, "[STACK] "+format, args...)
|
|
}
|