Skip to content

Commit

Permalink
logger: use env-aware slog handler for subsystems
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Jan 9, 2024
1 parent 843c961 commit 4d77963
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion coordinator/coordapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newCoordAPIServer(mSGetter manifestSetGetter, caGetter certChainGetter, log
policyTextStore: memstore.New[manifest.HexString, manifest.Policy](),
manifSetGetter: mSGetter,
caChainGetter: caGetter,
logger: log.WithGroup("coordapi"),
logger: log.WithGroup("coord-api"),
}
coordapi.RegisterCoordAPIServer(s.grpc, s)
return s
Expand Down
8 changes: 6 additions & 2 deletions coordinator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package main
import (
"errors"
"fmt"
"log/slog"
"net"
"os"

"github.com/edgelesssys/nunki/internal/ca"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/intercom"
"github.com/edgelesssys/nunki/internal/logger"
)

func main() {
Expand All @@ -19,7 +19,11 @@ func main() {
}

func run() (retErr error) {
logger := slog.Default()
logger, err := logger.Default()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: creating logger: %v\n", err)
return err
}
defer func() {
if retErr != nil {
logger.Error(retErr.Error())
Expand Down
8 changes: 6 additions & 2 deletions initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"log/slog"
"net"
"os"
"time"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/edgelesssys/nunki/internal/attestation/snp"
"github.com/edgelesssys/nunki/internal/grpc/dialer"
"github.com/edgelesssys/nunki/internal/intercom"
"github.com/edgelesssys/nunki/internal/logger"
)

func main() {
Expand All @@ -29,7 +29,11 @@ func main() {
}

func run() (retErr error) {
logger := slog.Default()
logger, err := logger.Default()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: creating logger: %v\n", err)
return err
}
defer func() {
if retErr != nil {
logger.Error(retErr.Error())
Expand Down
4 changes: 3 additions & 1 deletion internal/attestation/snp/cachedClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package snp
import (
"log/slog"

"github.com/edgelesssys/nunki/internal/logger"
"github.com/edgelesssys/nunki/internal/memstore"
"github.com/google/go-sev-guest/verify/trust"
)
Expand All @@ -16,9 +17,10 @@ type cachedKDSHTTPClient struct {

func newCachedKDSHTTPClient(log *slog.Logger) *cachedKDSHTTPClient {
trust.DefaultHTTPSGetter()
handler := logger.NewHandler(log.Handler(), "cached-kds-http-client")
return &cachedKDSHTTPClient{
HTTPSGetter: trust.DefaultHTTPSGetter(),
logger: log.WithGroup("cached-kds-http-client"),
logger: slog.New(handler),
cache: memstore.New[string, cacheEntry](),
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/attestation/snp/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"
"log/slog"

"github.com/edgelesssys/nunki/internal/logger"
"github.com/google/go-sev-guest/client"
)

Expand All @@ -24,7 +25,7 @@ type Issuer struct {

// NewIssuer returns a new Issuer.
func NewIssuer(log *slog.Logger) *Issuer {
return &Issuer{logger: log.WithGroup("snp-issuer")}
return &Issuer{logger: slog.New(logger.NewHandler(log.Handler(), "snp-issuer"))}
}

// OID returns the OID of the issuer.
Expand Down
6 changes: 4 additions & 2 deletions internal/attestation/snp/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"
"log/slog"

"github.com/edgelesssys/nunki/internal/logger"
"github.com/google/go-sev-guest/abi"
"github.com/google/go-sev-guest/proto/sevsnp"
"github.com/google/go-sev-guest/validate"
Expand Down Expand Up @@ -51,9 +52,10 @@ func (v *StaticValidateOptsGenerator) SNPValidateOpts(_ *sevsnp.Report) (*valida

// NewValidator returns a new Validator.
func NewValidator(optsGen validateOptsGenerator, log *slog.Logger) *Validator {
handler := logger.NewHandler(log.Handler(), "snp-validator")
return &Validator{
validateOptsGen: optsGen,
logger: log.WithGroup("snp-validator"),
logger: slog.New(handler),
}
}

Expand All @@ -63,7 +65,7 @@ func NewValidatorWithCallbacks(optsGen validateOptsGenerator, log *slog.Logger,
validateOptsGen: optsGen,
callbackers: callbacks,
kdsGetter: newCachedKDSHTTPClient(log),
logger: log.WithGroup("snp-validator"),
logger: slog.New(logger.NewHandler(log.Handler(), "snp-validator")),
}
}

Expand Down
8 changes: 6 additions & 2 deletions tools/parsesnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"encoding/hex"
"fmt"
"io"
"log/slog"
"os"

"github.com/edgelesssys/nunki/internal/logger"
"github.com/google/go-sev-guest/abi"
)

Expand Down Expand Up @@ -51,7 +51,11 @@ func main() {
}

func run() (retErr error) {
logger := slog.Default()
logger, err := logger.Default()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: creating logger: %v\n", err)
return err
}
defer func() {
if retErr != nil {
logger.Error(retErr.Error())
Expand Down

0 comments on commit 4d77963

Please sign in to comment.