Skip to content

Commit

Permalink
feat: add remote logging to important errors
Browse files Browse the repository at this point in the history
As convention always as 1st field, so it looks nice in console mode and matches existing logging
  • Loading branch information
ydylla committed Sep 9, 2022
1 parent 1e85a1a commit 522baa7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion layer4/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ func (mset MatcherSet) Match(cx *Connection, logger *zap.Logger) (matched bool,
cx.rewind()
if logger.Core().Enabled(zap.DebugLevel) {
logger.Debug("matching",
zap.String("remote", cx.RemoteAddr().String()),
zap.Error(err),
zap.String("matcher", m.CaddyModule().String()),
zap.Bool("matched", matched),
zap.Error(err),
)
}
if !matched || err != nil {
Expand Down
2 changes: 1 addition & 1 deletion layer4/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func wrapRoute(route *Route, logger *zap.Logger) Middleware {
// route must match at least one of the matcher sets
matched, err := route.matcherSets.AnyMatch(cx, logger)
if err != nil {
logger.Error("matching connection", zap.Error(err))
logger.Error("matching connection", zap.String("remote", cx.RemoteAddr().String()), zap.Error(err))
return nil // return nil so the error does not get logged again
}
if !matched {
Expand Down
2 changes: 1 addition & 1 deletion layer4/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s Server) handle(conn net.Conn) {
err := s.compiledRoute.Handle(cx)
duration := time.Since(start)
if err != nil {
s.logger.Error("handling connection", zap.Error(err))
s.logger.Error("handling connection", zap.String("remote", cx.RemoteAddr().String()), zap.Error(err))
}

s.logger.Debug("connection stats",
Expand Down
2 changes: 1 addition & 1 deletion modules/l4tee/tee.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (t Handler) Handle(cx *layer4.Connection, next layer4.Handler) error {
go func() {
err := t.compiledChain.Handle(&branchc)
if err != nil {
t.logger.Error("handling connection in branch", zap.Error(err))
t.logger.Error("handling connection in branch", zap.String("remote", cx.RemoteAddr().String()), zap.Error(err))
}
}()

Expand Down

0 comments on commit 522baa7

Please sign in to comment.