mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
Improve: redirect stack log
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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 (e emitter) Emit(_ int, level glog.Level, _ time.Time, format string, args ...any) {
|
||||
logf(Level(level)+2, "[STACK] "+format, args...)
|
||||
}
|
||||
Reference in New Issue
Block a user