mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
53 lines
773 B
Go
53 lines
773 B
Go
|
package tunnel
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
INFO LogType = iota
|
||
|
WARNING
|
||
|
ERROR
|
||
|
DEBUG
|
||
|
)
|
||
|
|
||
|
type LogType int
|
||
|
|
||
|
type Log struct {
|
||
|
LogType LogType
|
||
|
Payload string
|
||
|
}
|
||
|
|
||
|
func print(data Log) {
|
||
|
switch data.LogType {
|
||
|
case INFO:
|
||
|
log.Infoln(data.Payload)
|
||
|
case WARNING:
|
||
|
log.Warnln(data.Payload)
|
||
|
case ERROR:
|
||
|
log.Errorln(data.Payload)
|
||
|
case DEBUG:
|
||
|
log.Debugln(data.Payload)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (t *Tunnel) subscribeLogs() {
|
||
|
sub, err := t.observable.Subscribe()
|
||
|
if err != nil {
|
||
|
log.Fatalf("Can't subscribe tunnel log: %s", err.Error())
|
||
|
}
|
||
|
for elm := range sub {
|
||
|
data := elm.(Log)
|
||
|
print(data)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func newLog(logType LogType, format string, v ...interface{}) Log {
|
||
|
return Log{
|
||
|
LogType: logType,
|
||
|
Payload: fmt.Sprintf(format, v...),
|
||
|
}
|
||
|
}
|