update logging
This commit is contained in:
@@ -203,7 +203,7 @@ func (p *Pool) SetDialer(d types.Dialer) {
|
||||
|
||||
func (p *Pool) Close() {
|
||||
if p.logger != nil {
|
||||
p.logger.Debug("closing")
|
||||
p.logger.Info("closing")
|
||||
}
|
||||
|
||||
p.mu.Lock()
|
||||
@@ -233,7 +233,7 @@ func (p *Pool) Close() {
|
||||
|
||||
func (p *Pool) Connect(id string) error {
|
||||
if p.logger != nil {
|
||||
p.logger.Debug("connecting to peer", "peer", id)
|
||||
p.logger.Info("connecting", "peer", id)
|
||||
}
|
||||
|
||||
id, err := transport.NormalizeURL(id)
|
||||
@@ -273,7 +273,7 @@ func (p *Pool) Connect(id string) error {
|
||||
p.peers[id] = &Peer{id: id, worker: worker}
|
||||
|
||||
if p.logger != nil {
|
||||
p.logger.Info("registered peer", "peer", id)
|
||||
p.logger.Debug("registered peer", "peer", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -281,7 +281,7 @@ func (p *Pool) Connect(id string) error {
|
||||
|
||||
func (p *Pool) Remove(id string) error {
|
||||
if p.logger != nil {
|
||||
p.logger.Debug("disconnecting from peer", "peer", id)
|
||||
p.logger.Info("disconnecting", "peer", id)
|
||||
}
|
||||
|
||||
id, err := transport.NormalizeURL(id)
|
||||
@@ -305,7 +305,7 @@ func (p *Pool) Remove(id string) error {
|
||||
peer.worker.Stop()
|
||||
|
||||
if p.logger != nil {
|
||||
p.logger.Info("disconnected from peer", "peer", id)
|
||||
p.logger.Debug("disconnected from peer", "peer", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -219,7 +219,7 @@ func (c *Connection) Connect(ctx context.Context) error {
|
||||
// socket acquisition failed
|
||||
c.state = StateDisconnected
|
||||
if c.logger != nil {
|
||||
c.logger.Error("connection failed", "error", err)
|
||||
c.logger.Warn("connection failed", "error", err)
|
||||
}
|
||||
return NewConnectionError(err)
|
||||
}
|
||||
@@ -244,7 +244,7 @@ func (c *Connection) Connect(ctx context.Context) error {
|
||||
c.state = StateConnected
|
||||
|
||||
if c.logger != nil {
|
||||
c.logger.Info("connected")
|
||||
c.logger.Debug("connected")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -357,7 +357,7 @@ func (c *Connection) classifyCloseError(err error) error {
|
||||
switch closeErr.Code {
|
||||
case websocket.CloseNormalClosure, websocket.CloseGoingAway:
|
||||
if c.logger != nil {
|
||||
c.logger.Info("connection closed by peer",
|
||||
c.logger.Debug("connection closed by peer",
|
||||
"code", closeErr.Code,
|
||||
"text", closeErr.Text,
|
||||
)
|
||||
@@ -366,7 +366,7 @@ func (c *Connection) classifyCloseError(err error) error {
|
||||
|
||||
default:
|
||||
if c.logger != nil {
|
||||
c.logger.Error("unexpected close",
|
||||
c.logger.Warn("unexpected close",
|
||||
"code", closeErr.Code,
|
||||
"text", closeErr.Text,
|
||||
)
|
||||
@@ -492,7 +492,7 @@ func (c *Connection) shutdownInner() {
|
||||
})
|
||||
|
||||
if c.logger != nil {
|
||||
c.logger.Info("closing")
|
||||
c.logger.Debug("closing")
|
||||
}
|
||||
|
||||
if c.socket != nil {
|
||||
@@ -518,7 +518,7 @@ func (c *Connection) shutdownCleanup() {
|
||||
close(c.errors)
|
||||
|
||||
if c.logger != nil {
|
||||
c.logger.Info("closed")
|
||||
c.logger.Debug("closed")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ func AcquireSocket(
|
||||
if !retryMgr.ShouldRetry() {
|
||||
// retry policy expired
|
||||
if logger != nil {
|
||||
logger.Error("dial failed, max retries reached",
|
||||
logger.Debug("dial failed, max retries reached",
|
||||
"error", err,
|
||||
"attempt", retryMgr.RetryCount()+1)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package honeybee
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -124,13 +125,13 @@ func (w *DefaultWorker) Start(pool PoolPlugin) {
|
||||
})
|
||||
|
||||
if w.logger != nil {
|
||||
w.logger.Info("started")
|
||||
w.logger.Debug("started")
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if w.logger != nil {
|
||||
w.logger.Info("stopped")
|
||||
w.logger.Debug("stopped")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +163,7 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
|
||||
case conn = <-newConn:
|
||||
if w.logger != nil {
|
||||
w.logger.Debug("session: connected")
|
||||
w.logger.Info("connected")
|
||||
}
|
||||
break preConn
|
||||
|
||||
@@ -171,7 +172,7 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
|
||||
case <-inactive():
|
||||
if w.logger != nil {
|
||||
w.logger.Info("keepalive: no activity observed")
|
||||
w.logger.Warn("keepalive: no activity observed")
|
||||
}
|
||||
timer.Reset(w.config.KeepaliveTimeout)
|
||||
spawnDialer()
|
||||
@@ -183,7 +184,7 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
pool.Events <- PoolEvent{ID: w.id, Kind: EventConnected, At: time.Now()}
|
||||
|
||||
if w.logger != nil {
|
||||
w.logger.Info("session: started")
|
||||
w.logger.Debug("session: started")
|
||||
}
|
||||
|
||||
// run session loop
|
||||
@@ -195,8 +196,14 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
|
||||
case data, ok := <-conn.Incoming():
|
||||
if !ok {
|
||||
var reason error
|
||||
select {
|
||||
case reason = <-conn.Errors():
|
||||
default:
|
||||
reason = fmt.Errorf("unknown")
|
||||
}
|
||||
if w.logger != nil {
|
||||
w.logger.Debug("reader: disconnected")
|
||||
w.logger.Info("websocket: closed", "reason", reason)
|
||||
}
|
||||
break conn_loop
|
||||
}
|
||||
@@ -210,9 +217,6 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
heartbeat()
|
||||
|
||||
case <-conn.Heartbeat():
|
||||
if w.logger != nil {
|
||||
w.logger.Debug("ping-pong heartbeat")
|
||||
}
|
||||
heartbeat()
|
||||
|
||||
case <-w.sendHeartbeat:
|
||||
@@ -220,7 +224,7 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
|
||||
case <-inactive():
|
||||
if w.logger != nil {
|
||||
w.logger.Info("keepalive: no activity observed")
|
||||
w.logger.Warn("keepalive: no activity observed")
|
||||
}
|
||||
timer.Reset(w.config.KeepaliveTimeout)
|
||||
break conn_loop
|
||||
@@ -231,7 +235,10 @@ func (w *DefaultWorker) runSession(ctx context.Context, pool PoolPlugin) {
|
||||
conn.Close()
|
||||
|
||||
if w.logger != nil {
|
||||
w.logger.Info("session: ended")
|
||||
w.logger.Info("disconnected")
|
||||
}
|
||||
if w.logger != nil {
|
||||
w.logger.Debug("session: ended")
|
||||
}
|
||||
|
||||
// tear down connection
|
||||
@@ -301,16 +308,13 @@ func (w *DefaultWorker) spawnDialer(
|
||||
dialCtx, dialCancel := context.WithCancel(ctx)
|
||||
|
||||
if w.logger != nil {
|
||||
w.logger.Debug("session: requesting connection")
|
||||
w.logger.Debug("session: dialing")
|
||||
}
|
||||
|
||||
go func() {
|
||||
conn, err := connect(w.id, dialCtx, pool, w.handler)
|
||||
|
||||
if err != nil {
|
||||
if w.logger != nil {
|
||||
w.logger.Warn("dialer: dial failed", "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -345,7 +349,7 @@ func connect(
|
||||
|
||||
func (w *DefaultWorker) Stop() {
|
||||
if w.logger != nil {
|
||||
w.logger.Debug("shutting down")
|
||||
w.logger.Info("shutting down")
|
||||
}
|
||||
w.cancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user