Skip to content

Commit 40ea6a5

Browse files
committed
TUN-6829: Allow user of datagramsession to control logging level of errors
1 parent 4642316 commit 40ea6a5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

datagramsession/session.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ func SessionIdleErr(timeout time.Duration) error {
2424

2525
type transportSender func(session *packet.Session) error
2626

27+
// ErrVithVariableSeverity are errors that have variable severity
28+
type ErrVithVariableSeverity interface {
29+
error
30+
// LogLevel return the severity of this error
31+
LogLevel() zerolog.Level
32+
}
33+
2734
// Session is a bidirectional pipe of datagrams between transport and dstConn
2835
// Destination can be a connection with origin or with eyeball
2936
// When the destination is origin:
@@ -53,7 +60,11 @@ func (s *Session) Serve(ctx context.Context, closeAfterIdle time.Duration) (clos
5360
if errors.Is(err, net.ErrClosed) {
5461
s.log.Debug().Msg("Destination connection closed")
5562
} else {
56-
s.log.Error().Err(err).Msg("Failed to send session payload from destination to transport")
63+
level := zerolog.ErrorLevel
64+
if variableErr, ok := err.(ErrVithVariableSeverity); ok {
65+
level = variableErr.LogLevel()
66+
}
67+
s.log.WithLevel(level).Err(err).Msg("Failed to send session payload from destination to transport")
5768
}
5869
if closeSession {
5970
s.closeChan <- err

0 commit comments

Comments
 (0)