mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-11 16:30:12 -04:00
tidy
This commit is contained in:
parent
d80383d993
commit
972f832a6e
10 changed files with 31 additions and 31 deletions
|
@ -11,12 +11,12 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/initproto"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/initproto"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/atls"
|
"github.com/edgelesssys/constellation/v2/internal/atls"
|
||||||
|
|
|
@ -9,12 +9,12 @@ package joinclient
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
|
|
|
@ -9,10 +9,10 @@ package kubernetes
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi"
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/kubewaiter"
|
||||||
|
|
|
@ -10,10 +10,10 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption"
|
"github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption"
|
||||||
"github.com/martinjungblut/go-cryptsetup"
|
"github.com/martinjungblut/go-cryptsetup"
|
||||||
|
|
|
@ -12,13 +12,13 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/bazelbuild/rules_go/go/runfiles"
|
"github.com/bazelbuild/rules_go/go/runfiles"
|
||||||
"github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption"
|
"github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption"
|
||||||
|
|
|
@ -5,6 +5,7 @@ go_library(
|
||||||
srcs = [
|
srcs = [
|
||||||
"cmdline.go",
|
"cmdline.go",
|
||||||
"grpclogger.go",
|
"grpclogger.go",
|
||||||
|
"levelhandler.go",
|
||||||
"log.go",
|
"log.go",
|
||||||
],
|
],
|
||||||
importpath = "github.com/edgelesssys/constellation/v2/internal/logger",
|
importpath = "github.com/edgelesssys/constellation/v2/internal/logger",
|
||||||
|
|
|
@ -26,14 +26,14 @@ func replaceGRPCLogger(log *slog.Logger) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) log(level slog.Level, args ...interface{}) {
|
func (l *grpcLogger) log(level slog.Level, args ...interface{}) {
|
||||||
var pcs [1]uintptr
|
var pcs [1]uintptr
|
||||||
runtime.Callers(3, pcs[:])
|
runtime.Callers(3, pcs[:])
|
||||||
r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0])
|
r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0])
|
||||||
_ = l.logger.Handler().Handle(context.Background(), r)
|
_ = l.logger.Handler().Handle(context.Background(), r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) logf(level slog.Level, format string, args ...interface{}) {
|
func (l *grpcLogger) logf(level slog.Level, format string, args ...interface{}) {
|
||||||
var pcs [1]uintptr
|
var pcs [1]uintptr
|
||||||
runtime.Callers(3, pcs[:])
|
runtime.Callers(3, pcs[:])
|
||||||
r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(format, args...), pcs[0])
|
r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(format, args...), pcs[0])
|
||||||
_ = l.logger.Handler().Handle(context.Background(), r)
|
_ = l.logger.Handler().Handle(context.Background(), r)
|
||||||
|
@ -45,53 +45,53 @@ type grpcLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Info(args ...interface{}) {
|
func (l *grpcLogger) Info(args ...interface{}) {
|
||||||
l.log(slog.LevelInfo, args...)
|
l.log(slog.LevelInfo, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Infoln(args ...interface{}) {
|
func (l *grpcLogger) Infoln(args ...interface{}) {
|
||||||
l.log(slog.LevelInfo, args...)
|
l.log(slog.LevelInfo, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Infof(format string, args ...interface{}) {
|
func (l *grpcLogger) Infof(format string, args ...interface{}) {
|
||||||
l.logf(slog.LevelInfo, format, args...)
|
l.logf(slog.LevelInfo, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Warning(args ...interface{}) {
|
func (l *grpcLogger) Warning(args ...interface{}) {
|
||||||
l.log(slog.LevelWarn, args...)
|
l.log(slog.LevelWarn, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Warningln(args ...interface{}) {
|
func (l *grpcLogger) Warningln(args ...interface{}) {
|
||||||
l.log(slog.LevelWarn, args...)
|
l.log(slog.LevelWarn, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Warningf(format string, args ...interface{}) {
|
func (l *grpcLogger) Warningf(format string, args ...interface{}) {
|
||||||
l.logf(slog.LevelWarn, format, args...)
|
l.logf(slog.LevelWarn, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Error(args ...interface{}) {
|
func (l *grpcLogger) Error(args ...interface{}) {
|
||||||
l.log(slog.LevelError, args...)
|
l.log(slog.LevelError, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Errorln(args ...interface{}) {
|
func (l *grpcLogger) Errorln(args ...interface{}) {
|
||||||
l.log(slog.LevelError, args...)
|
l.log(slog.LevelError, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Errorf(format string, args ...interface{}) {
|
func (l *grpcLogger) Errorf(format string, args ...interface{}) {
|
||||||
l.logf(slog.LevelError, format, args...)
|
l.logf(slog.LevelError, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Fatal(args ...interface{}) {
|
func (l *grpcLogger) Fatal(args ...interface{}) {
|
||||||
l.log(slog.LevelError, args...)
|
l.log(slog.LevelError, args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Fatalln(args ...interface{}) {
|
func (l *grpcLogger) Fatalln(args ...interface{}) {
|
||||||
l.log(slog.LevelError, args...)
|
l.log(slog.LevelError, args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *grpcLogger) Fatalf(format string, args ...interface{}) {
|
func (l *grpcLogger) Fatalf(format string, args ...interface{}) {
|
||||||
l.logf(slog.LevelError, format, args...)
|
l.logf(slog.LevelError, format, args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,11 @@ Copyright (c) Edgeless Systems GmbH
|
||||||
SPDX-License-Identifier: AGPL-3.0-only
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
"context"
|
||||||
"context"
|
"log/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LevelHandler copied from the official LevelHandler example in the slog package documentation.
|
// LevelHandler copied from the official LevelHandler example in the slog package documentation.
|
||||||
|
|
|
@ -19,7 +19,7 @@ You can create a new logger with a new log level by creating a new slog.Logger w
|
||||||
and passing the handler of the other logger. As an example, if you have a slog.Logger named `log` you can create a
|
and passing the handler of the other logger. As an example, if you have a slog.Logger named `log` you can create a
|
||||||
new logger with an increased log level (here slog.LevelWarn) like this:
|
new logger with an increased log level (here slog.LevelWarn) like this:
|
||||||
|
|
||||||
slog.New(logger.NewLevelHandler(slog.LevelWarn, log.Handler()))
|
slog.New(logger.NewLevelHandler(slog.LevelWarn, log.Handler()))
|
||||||
*/
|
*/
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
|
@ -90,13 +90,13 @@ func middlewareLogger(l *slog.Logger) logging.Logger {
|
||||||
|
|
||||||
var pcs [1]uintptr
|
var pcs [1]uintptr
|
||||||
runtime.Callers(2, pcs[:]) // skip [Callers, LoggerFunc]
|
runtime.Callers(2, pcs[:]) // skip [Callers, LoggerFunc]
|
||||||
level := slog.LevelDebug
|
level := slog.LevelDebug
|
||||||
|
|
||||||
switch lvl {
|
switch lvl {
|
||||||
case logging.LevelDebug:
|
case logging.LevelDebug:
|
||||||
break
|
break
|
||||||
case logging.LevelInfo:
|
case logging.LevelInfo:
|
||||||
level = slog.LevelInfo
|
level = slog.LevelInfo
|
||||||
case logging.LevelWarn:
|
case logging.LevelWarn:
|
||||||
level = slog.LevelWarn
|
level = slog.LevelWarn
|
||||||
case logging.LevelError:
|
case logging.LevelError:
|
||||||
|
@ -105,13 +105,13 @@ func middlewareLogger(l *slog.Logger) logging.Logger {
|
||||||
panic(fmt.Sprintf("unknown level %v", lvl))
|
panic(fmt.Sprintf("unknown level %v", lvl))
|
||||||
}
|
}
|
||||||
|
|
||||||
r := slog.NewRecord(time.Now(), level, fmt.Sprintf(msg, fields...), pcs[0])
|
r := slog.NewRecord(time.Now(), level, fmt.Sprintf(msg, fields...), pcs[0])
|
||||||
_ = l.Handler().Handle(context.Background(), r)
|
_ = l.Handler().Handle(context.Background(), r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTest(t * testing.T) *slog.Logger {
|
func NewTest(t *testing.T) *slog.Logger {
|
||||||
return slog.New(slog.NewTextHandler(testWriter{t: t}, nil))
|
return slog.New(slog.NewTextHandler(testWriter{t: t}, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestWriter is a writer to a testing.T used in tests for logging with slog.
|
// TestWriter is a writer to a testing.T used in tests for logging with slog.
|
||||||
|
|
|
@ -8,8 +8,8 @@ package amdkds
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"testing"
|
"testing"
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||||
"github.com/edgelesssys/constellation/v2/joinservice/internal/certcache/amdkds/testdata"
|
"github.com/edgelesssys/constellation/v2/joinservice/internal/certcache/amdkds/testdata"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue