can set logger compatiable with logrus
This commit is contained in:
parent
ef798c1ac7
commit
c385a6b1ea
@ -10,6 +10,11 @@ type Connection struct {
|
|||||||
TX chan<- *DataFrame
|
TX chan<- *DataFrame
|
||||||
ID ID
|
ID ID
|
||||||
closed bool
|
closed bool
|
||||||
|
logger Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Connection) SetLogger(logger Logger) {
|
||||||
|
c.logger = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) Read(p []byte) (int, error) {
|
func (c *Connection) Read(p []byte) (int, error) {
|
||||||
|
43
logger.go
Normal file
43
logger.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package tunnel
|
||||||
|
|
||||||
|
type Logger interface {
|
||||||
|
Trace(args ...interface{})
|
||||||
|
Tracef(format string, args ...interface{})
|
||||||
|
|
||||||
|
Debug(args ...interface{})
|
||||||
|
Debugf(format string, args ...interface{})
|
||||||
|
|
||||||
|
Info(args ...interface{})
|
||||||
|
Infof(format string, args ...interface{})
|
||||||
|
|
||||||
|
Error(args ...interface{})
|
||||||
|
Errorf(format string, args ...interface{})
|
||||||
|
|
||||||
|
Fatal(args ...interface{})
|
||||||
|
Fatalf(format string, args ...interface{})
|
||||||
|
|
||||||
|
Panic(args ...interface{})
|
||||||
|
Panicf(format string, args ...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type logger struct{}
|
||||||
|
|
||||||
|
func (l *logger) Trace(args ...interface{})
|
||||||
|
func (l *logger) Tracef(format string, args ...interface{})
|
||||||
|
|
||||||
|
func (l *logger) Debug(args ...interface{})
|
||||||
|
func (l *logger) Debugf(format string, args ...interface{})
|
||||||
|
|
||||||
|
func (l *logger) Info(args ...interface{})
|
||||||
|
func (l *logger) Infof(format string, args ...interface{})
|
||||||
|
|
||||||
|
func (l *logger) Error(args ...interface{})
|
||||||
|
func (l *logger) Errorf(format string, args ...interface{})
|
||||||
|
|
||||||
|
func (l *logger) Fatal(args ...interface{})
|
||||||
|
func (l *logger) Fatalf(format string, args ...interface{})
|
||||||
|
|
||||||
|
func (l *logger) Panic(args ...interface{})
|
||||||
|
func (l *logger) Panicf(format string, args ...interface{})
|
||||||
|
|
||||||
|
var DefaultLogger = &logger{}
|
@ -13,6 +13,7 @@ type Manager struct {
|
|||||||
closed chan bool
|
closed chan bool
|
||||||
newConnection chan *Connection
|
newConnection chan *Connection
|
||||||
delConnection chan *Connection
|
delConnection chan *Connection
|
||||||
|
logger Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(tun io.ReadWriter) *Manager {
|
func NewManager(tun io.ReadWriter) *Manager {
|
||||||
@ -24,9 +25,14 @@ func NewManager(tun io.ReadWriter) *Manager {
|
|||||||
accept: make(chan *DataFrame, 1024),
|
accept: make(chan *DataFrame, 1024),
|
||||||
newConnection: make(chan *Connection),
|
newConnection: make(chan *Connection),
|
||||||
delConnection: make(chan *Connection),
|
delConnection: make(chan *Connection),
|
||||||
|
logger: DefaultLogger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) SetLogger(logger Logger) {
|
||||||
|
m.logger = logger
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) Run() {
|
func (m *Manager) Run() {
|
||||||
onReceiveQueue := make(chan bool)
|
onReceiveQueue := make(chan bool)
|
||||||
for {
|
for {
|
||||||
@ -77,6 +83,7 @@ func (m *Manager) Connect() (*Connection, error) {
|
|||||||
connection := &Connection{
|
connection := &Connection{
|
||||||
ID: df.ID,
|
ID: df.ID,
|
||||||
TX: m.incoming,
|
TX: m.incoming,
|
||||||
|
logger: DefaultLogger,
|
||||||
}
|
}
|
||||||
m.newConnection <- connection
|
m.newConnection <- connection
|
||||||
m.incoming <- df
|
m.incoming <- df
|
||||||
@ -96,6 +103,7 @@ func (m *Manager) Accept() (*Connection, error) {
|
|||||||
connection := &Connection{
|
connection := &Connection{
|
||||||
ID: df.ID,
|
ID: df.ID,
|
||||||
TX: m.incoming,
|
TX: m.incoming,
|
||||||
|
logger: DefaultLogger,
|
||||||
}
|
}
|
||||||
m.newConnection <- connection
|
m.newConnection <- connection
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user