gfwproxyshadowsocksdocker-imagegogolanggvisornatnetworksocks4socks5tcpip-stacktortun-devicetun2sockstunneludpwireguard
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
711 B
39 lines
711 B
package log
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/xjasonlyu/tun2socks/v2/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)
|
|
}
|
|
|