Init: first commit 🎉
This commit is contained in:
52
tunnel/log.go
Normal file
52
tunnel/log.go
Normal file
@ -0,0 +1,52 @@
|
||||
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...),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user