Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
punmechanic committed Mar 27, 2024
1 parent 0a2e8e6 commit c209e39
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"net/http"

"golang.org/x/exp/slog"
"log/slog"
)

type LogRoundTripper struct {
Expand Down
3 changes: 2 additions & 1 deletion cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"
"os"

"log/slog"

"github.com/pkg/browser"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/exp/slog"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"strings"
"syscall"

"log/slog"

"github.com/spf13/cobra"
"golang.org/x/exp/slog"
)

const (
Expand Down
8 changes: 7 additions & 1 deletion cli/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -165,9 +166,14 @@ var ErrNoPortsAvailable = errors.New("no ports available")
func findFirstFreePort(ctx context.Context, broadcastAddr string, ports []string) (net.Listener, error) {
var lc net.ListenConfig
for _, port := range ports {
sock, err := lc.Listen(ctx, "tcp4", net.JoinHostPort(broadcastAddr, port))
addr := net.JoinHostPort(broadcastAddr, port)
slog.Debug("opening connection", slog.String("addr", addr))
sock, err := lc.Listen(ctx, "tcp4", addr)
if err == nil {
slog.Debug("listening", slog.String("addr", addr))
return sock, nil
} else {
slog.Debug("could not listen, trying a different addr", slog.String("addr", addr), slog.String("error", err.Error()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

"golang.org/x/exp/slog"
"log/slog"

Check failure on line 7 in internal/api/http.go

View workflow job for this annotation

GitHub Actions / go-test

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.19.13/x64/src/log/slog)
)

// RequestAttrs returns attributes to be used with slog for the given request.
Expand Down
2 changes: 1 addition & 1 deletion internal/api/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"net/http"

"golang.org/x/exp/slog"
"log/slog"
)

func ServeJSON[T any](w http.ResponseWriter, data T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/api/serverless_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"net/http"
"strings"

"log/slog"

"github.com/okta/okta-sdk-golang/v2/okta"
"golang.org/x/exp/slog"
)

type Application struct {
Expand Down
3 changes: 2 additions & 1 deletion lambda/list_applications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"net/url"
"os"

"log/slog"

"github.com/aws/aws-lambda-go/lambda"
"github.com/riotgames/key-conjurer/internal"
"github.com/riotgames/key-conjurer/internal/api"
"golang.org/x/exp/slog"
)

func main() {
Expand Down

0 comments on commit c209e39

Please sign in to comment.