core: replace zap with logtree

Test Plan: Effective refactor. Only tests that could be affected are e2e tests that should continue to run, because we still are logging into the qemu console, even if differently.

X-Origin-Diff: phab/D642
GitOrigin-RevId: 0f12b1bc985af08a3cc269569273184321763e4b
diff --git a/core/pkg/tpm/BUILD.bazel b/core/pkg/tpm/BUILD.bazel
index c39055f..648a9db 100644
--- a/core/pkg/tpm/BUILD.bazel
+++ b/core/pkg/tpm/BUILD.bazel
@@ -9,6 +9,7 @@
     importpath = "git.monogon.dev/source/nexantic.git/core/pkg/tpm",
     visibility = ["//visibility:public"],
     deps = [
+        "//core/pkg/logtree:go_default_library",
         "//core/pkg/sysfs:go_default_library",
         "@com_github_gogo_protobuf//proto:go_default_library",
         "@com_github_google_go_tpm//tpm2:go_default_library",
@@ -17,6 +18,5 @@
         "@com_github_google_go_tpm_tools//tpm2tools:go_default_library",
         "@com_github_pkg_errors//:go_default_library",
         "@org_golang_x_sys//unix:go_default_library",
-        "@org_uber_go_zap//:go_default_library",
     ],
 )
diff --git a/core/pkg/tpm/tpm.go b/core/pkg/tpm/tpm.go
index 5914b35..6fda219 100644
--- a/core/pkg/tpm/tpm.go
+++ b/core/pkg/tpm/tpm.go
@@ -28,9 +28,12 @@
 	"os"
 	"path/filepath"
 	"strconv"
+	"strings"
 	"sync"
 	"time"
 
+	"git.monogon.dev/source/nexantic.git/core/pkg/logtree"
+
 	"git.monogon.dev/source/nexantic.git/core/pkg/sysfs"
 
 	"github.com/gogo/protobuf/proto"
@@ -39,7 +42,6 @@
 	"github.com/google/go-tpm/tpm2"
 	"github.com/google/go-tpm/tpmutil"
 	"github.com/pkg/errors"
-	"go.uber.org/zap"
 	"golang.org/x/sys/unix"
 )
 
@@ -114,7 +116,7 @@
 
 // TPM represents a high-level interface to a connected TPM 2.0
 type TPM struct {
-	logger *zap.Logger
+	logger logtree.LeveledLogger
 	device io.ReadWriteCloser
 
 	// We keep the AK loaded since it's used fairly often and deriving it is expensive
@@ -124,7 +126,7 @@
 
 // Initialize finds and opens the TPM (if any). If there is no TPM available it returns
 // ErrNotExists
-func Initialize(logger *zap.Logger) error {
+func Initialize(logger logtree.LeveledLogger) error {
 	lock.Lock()
 	defer lock.Unlock()
 	tpmDir, err := os.Open("/sys/class/tpm")
@@ -143,7 +145,7 @@
 	}
 	if len(tpms) > 1 {
 		// If this is changed GetMeasurementLog() needs to be updated too
-		logger.Warn("Found more than one TPM, using the first one")
+		logger.Warningf("Found more than one TPM, using the first one")
 	}
 	tpmName := tpms[0]
 	ueventData, err := sysfs.ReadUevents(filepath.Join("/sys/class/tpm", tpmName, "uevent"))
@@ -243,7 +245,11 @@
 		return []byte{}, errors.Wrap(err, "failed to decode sealed data")
 	}
 	// Logging this for auditing purposes
-	tpm.logger.Info("Attempting to unseal data protected with PCRs", zap.Int32s("pcrs", sealedKey.Pcrs))
+	pcrList := []string{}
+	for _, pcr := range sealedKey.Pcrs {
+		pcrList = append(pcrList, string(pcr))
+	}
+	tpm.logger.Infof("Attempting to unseal data protected with PCRs %s", strings.Join(pcrList, ","))
 	unsealedData, err := srk.Unseal(&sealedKey)
 	if err != nil {
 		return []byte{}, errors.Wrap(err, "failed to unseal data")