-
Notifications
You must be signed in to change notification settings - Fork 83
/
log.go
41 lines (34 loc) · 864 Bytes
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package tun2socks
import (
alog "github.com/xtls/xray-core/app/log"
"github.com/xtls/xray-core/common"
vcommonlog "github.com/xtls/xray-core/common/log"
)
type LogService interface {
WriteLog(s string) error
}
type logWriter struct {
logger *LogService
}
func (w *logWriter) Write(s string) error {
(*w.logger).WriteLog(s)
return nil
}
func (w *logWriter) Close() error {
return nil
}
func createLogWriter(logService LogService) vcommonlog.WriterCreator {
return func() vcommonlog.Writer {
return &logWriter{
logger: &logService,
}
}
}
func registerLogService(logService LogService) {
if logService != nil {
common.Must(alog.RegisterHandlerCreator(alog.LogType_Console, func(lt alog.LogType,
options alog.HandlerCreatorOptions) (vcommonlog.Handler, error) {
return vcommonlog.NewLogger(createLogWriter(logService)), nil
}))
}
}