Skip to content

Commit

Permalink
added staticlink check and updated setLogger to log kvs
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Jun 14, 2023
1 parent 12be349 commit 44382da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions basculeLogging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -29,13 +30,24 @@ func setLogger(logger *zap.Logger) func(delegate http.Handler) http.Handler {
func(w http.ResponseWriter, r *http.Request) {
kvs := []interface{}{"requestHeaders", sanitizeHeaders(r.Header), "requestURL", r.URL.EscapedPath(), "method", r.Method}
kvs, _ = candlelight.AppendTraceInfo(r.Context(), kvs)
ctx := r.WithContext(sallust.With(r.Context(), logger))
delegate.ServeHTTP(w, ctx)
ctx := r.Context()
ctx = addFieldsToLog(ctx, logger, kvs)
delegate.ServeHTTP(w, r.WithContext(ctx))
})
}
}

func getLogger(ctx context.Context) *zap.Logger {
logger := sallust.Get(ctx).With(zap.Time("ts", time.Now().UTC()), zap.Any("caller", zap.WithCaller(true)))
return logger
}
}

func addFieldsToLog(ctx context.Context, logger *zap.Logger, kvs []interface{}) context.Context {

for i := 0; i <= len(kvs)-2; i += 2 {
logger = logger.With(zap.Any(fmt.Sprint(kvs[i]), kvs[i+1]))
}

return sallust.With(ctx, logger)

}
1 change: 1 addition & 0 deletions primaryHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/xmidt-org/webpa-common/v2/adapter"
// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/xmetrics"
)

Expand Down

0 comments on commit 44382da

Please sign in to comment.