This commit is contained in:
xjasonlyu
2021-02-05 20:02:29 +08:00
parent 60d61eee7a
commit 90d7d2dfe6
92 changed files with 3176 additions and 1689 deletions

39
log/event.go Executable file
View File

@@ -0,0 +1,39 @@
package log
import (
"fmt"
"time"
"github.com/xjasonlyu/tun2socks/common/observable"
)
var (
logCh = make(chan interface{})
source = observable.NewObservable(logCh)
)
type Event struct {
Level Level `json:"level"`
Message string `json:"msg"`
Time time.Time `json:"time"`
}
func newEvent(level Level, format string, args ...interface{}) *Event {
event := &Event{
Level: level,
Time: time.Now(),
Message: fmt.Sprintf(format, args...),
}
logCh <- event /* send all events to logCh */
return event
}
func Subscribe() observable.Subscription {
sub, _ := source.Subscribe()
return sub
}
func UnSubscribe(sub observable.Subscription) {
source.UnSubscribe(sub)
}