Skip to content

Commit

Permalink
rewrote every slog logger to add source
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf committed Jan 31, 2024
1 parent 147e7c2 commit ec7f294
Show file tree
Hide file tree
Showing 34 changed files with 72 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bootstrapper/cmd/bootstrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
gRPCDebug := flag.Bool("debug", false, "Enable gRPC debug logging")
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
flag.Parse()
log := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)})).WithGroup("bootstrapper")
log := logger.NewJSONLogger(logger.VerbosityFromInt(*verbosity)).WithGroup("bootstrapper")

if *gRPCDebug {
logger.ReplaceGRPCLogger(log.WithGroup("gRPC"))
Expand Down
4 changes: 2 additions & 2 deletions cli/internal/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package cmd

import (
"log/slog"
"os"

"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand All @@ -27,5 +27,5 @@ func newCLILogger(cmd *cobra.Command) (debugLog, error) {
logLvl = slog.LevelDebug
}

return slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logLvl})), nil
return logger.NewTextLogger(logLvl), nil
}
2 changes: 1 addition & 1 deletion debugd/cmd/debugd/debugd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)
flag.Parse()

log := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)}))
log := logger.NewJSONLogger(logger.VerbosityFromInt(*verbosity))
fs := afero.NewOsFs()
streamer := streamer.New(fs)
filetransferer := filetransfer.New(log.WithGroup("filetransfer"), streamer, filetransfer.DontShowProgress)
Expand Down
3 changes: 1 addition & 2 deletions debugd/internal/cdbg/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"fmt"
"log/slog"
"net"
"os"
"path/filepath"
"strconv"
"sync"
Expand Down Expand Up @@ -62,7 +61,7 @@ func runDeploy(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logger.VerbosityFromInt(verbosity)}))
log := logger.NewTextLogger(logger.VerbosityFromInt(verbosity))
force, err := cmd.Flags().GetBool("force")
if err != nil {
return fmt.Errorf("getting force flag: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion disk-mapper/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
verbosity := flag.Int("v", 0, logger.CmdLineVerbosityDescription)

flag.Parse()
log := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: logger.VerbosityFromInt(*verbosity)}))
log := logger.NewJSONLogger(logger.VerbosityFromInt(*verbosity))
log.With(slog.String("version", constants.BinaryVersion().String()), slog.String("cloudProvider", *csp)).
Info("Starting disk-mapper")

Expand Down
3 changes: 2 additions & 1 deletion disk-mapper/internal/test/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption"
"github.com/martinjungblut/go-cryptsetup"
"github.com/edgelesssys/constellation/v2/internal/logger"
)

func BenchmarkMapper(b *testing.B) {
Expand All @@ -39,7 +40,7 @@ func BenchmarkMapper(b *testing.B) {
}

passphrase := "benchmark"
mapper, free, err := diskencryption.New(testPath, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo})))
mapper, free, err := diskencryption.New(testPath, logger.NewTextLogger(slog.LevelInfo))
if err != nil {
b.Fatal("Failed to create mapper:", err)
}
Expand Down
3 changes: 2 additions & 1 deletion disk-mapper/internal/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"github.com/edgelesssys/constellation/v2/internal/logger"
)

const (
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestMapper(t *testing.T) {
require.NoError(setup(1), "failed to setup test disk")
defer func() { require.NoError(teardown(), "failed to delete test disk") }()

mapper, free, err := diskencryption.New(devicePath, slog.New(slog.NewTextHandler(os.Stderr, nil)))
mapper, free, err := diskencryption.New(devicePath, logger.NewTextLogger(slog.LevelInfo))
require.NoError(err, "failed to initialize crypt device")
defer free()

Expand Down
3 changes: 2 additions & 1 deletion e2e/malicious-join/malicious-join.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/grpc/dialer"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/joinservice/joinproto"
)

func main() {
log := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
log := logger.NewJSONLogger(slog.LevelDebug)

jsEndpoint := flag.String("js-endpoint", "", "Join service endpoint to use.")
csp := flag.String("csp", "", "Cloud service provider to use.")
Expand Down
4 changes: 2 additions & 2 deletions hack/bazel-deps-mirror/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/bazelfiles"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/issues"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/mirror"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/rules"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand All @@ -39,7 +39,7 @@ func runCheck(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

filesHelper, err := bazelfiles.New()
Expand Down
4 changes: 2 additions & 2 deletions hack/bazel-deps-mirror/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/bazelbuild/buildtools/build"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/bazelfiles"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/issues"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/mirror"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/rules"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand All @@ -39,7 +39,7 @@ func runFix(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

fileHelper, err := bazelfiles.New()
Expand Down
4 changes: 2 additions & 2 deletions hack/bazel-deps-mirror/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/bazelbuild/buildtools/build"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/bazelfiles"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/issues"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/mirror"
"github.com/edgelesssys/constellation/v2/hack/bazel-deps-mirror/internal/rules"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand All @@ -39,7 +39,7 @@ func runUpgrade(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

fileHelper, err := bazelfiles.New()
Expand Down
3 changes: 2 additions & 1 deletion hack/cli-k8s-compatibility/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/edgelesssys/constellation/v2/internal/api/versionsapi"
"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/internal/versions"
)

Expand All @@ -26,7 +27,7 @@ var (
)

func main() {
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
log := logger.NewTextLogger(slog.LevelDebug)
ctx := context.Background()

flag.Parse()
Expand Down
3 changes: 2 additions & 1 deletion hack/oci-pin/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/edgelesssys/constellation/v2/hack/oci-pin/internal/extract"
"github.com/edgelesssys/constellation/v2/hack/oci-pin/internal/inject"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -43,7 +44,7 @@ func runCodegen(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

registry, prefix, name, tag, err := splitRepoTag(flags.imageRepoTag)
Expand Down
3 changes: 2 additions & 1 deletion hack/oci-pin/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"

"github.com/edgelesssys/constellation/v2/hack/oci-pin/internal/sums"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand All @@ -34,7 +35,7 @@ func runMerge(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

log.Debug(fmt.Sprintf("Merging sum file from %q into %q.", flags.inputs, flags.output))
Expand Down
3 changes: 2 additions & 1 deletion hack/oci-pin/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/edgelesssys/constellation/v2/hack/oci-pin/internal/extract"
"github.com/edgelesssys/constellation/v2/hack/oci-pin/internal/sums"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand All @@ -40,7 +41,7 @@ func runSum(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

registry, prefix, name, tag, err := splitRepoTag(flags.imageRepoTag)
Expand Down
3 changes: 2 additions & 1 deletion hack/qemu-metadata-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/server"
"github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper"
"github.com/edgelesssys/constellation/v2/internal/logger"
"libvirt.org/go/libvirt"
)

Expand All @@ -25,7 +26,7 @@ func main() {
initSecretHash := flag.String("initsecrethash", "", "brcypt hash of the init secret")
flag.Parse()

log := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo}))
log := logger.NewJSONLogger(slog.LevelInfo)

conn, err := libvirt.NewConnect(*libvirtURI)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions image/upload/internal/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ package cmd
import (
"encoding/json"
"fmt"
"log/slog"
"os"

"github.com/edgelesssys/constellation/v2/internal/api/versionsapi"
"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/edgelesssys/constellation/v2/internal/logger"
infoupload "github.com/edgelesssys/constellation/v2/internal/osimage/imageinfo"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -49,7 +49,7 @@ func runInfo(cmd *cobra.Command, args []string) error {
return err
}

log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))
info, err := readInfoArgs(args)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions image/upload/internal/cmd/measurementsenvelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ package cmd
import (
"encoding/json"
"fmt"
"log/slog"
"os"

"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ func runEnvelopeMeasurements(cmd *cobra.Command, _ []string) error {
return err
}

log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

f, err := os.Open(flags.in)
Expand Down
4 changes: 2 additions & 2 deletions image/upload/internal/cmd/measurementsmerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ package cmd
import (
"encoding/json"
"fmt"
"log/slog"
"os"

"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -44,7 +44,7 @@ func runMergeMeasurements(cmd *cobra.Command, args []string) error {
return err
}

log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

mergedMeasurements, err := readMeasurementsArgs(args)
Expand Down
4 changes: 2 additions & 2 deletions image/upload/internal/cmd/measurementsupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package cmd

import (
"fmt"
"log/slog"
"os"

"github.com/edgelesssys/constellation/v2/internal/constants"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/internal/osimage/measurementsuploader"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ func runMeasurementsUpload(cmd *cobra.Command, _ []string) error {
return err
}

log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

uploadC, uploadCClose, err := measurementsuploader.New(cmd.Context(), flags.region, flags.bucket, flags.distributionID, log)
Expand Down
4 changes: 2 additions & 2 deletions image/upload/internal/cmd/uplosi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ package cmd
import (
"fmt"
"io"
"log/slog"
"os"
"strconv"
"time"

"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/logger"
"github.com/edgelesssys/constellation/v2/internal/osimage"
"github.com/edgelesssys/constellation/v2/internal/osimage/archive"
nopupload "github.com/edgelesssys/constellation/v2/internal/osimage/nop"
Expand Down Expand Up @@ -58,7 +58,7 @@ func runUplosi(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: flags.logLevel}))
log := logger.NewTextLogger(flags.logLevel)
log.Debug(fmt.Sprintf("Parsed flags: %+v", flags))

archiveC, archiveCClose, err := archive.New(cmd.Context(), flags.region, flags.bucket, flags.distributionID, log)
Expand Down
Loading

0 comments on commit ec7f294

Please sign in to comment.