From 557b4dce44de75a69d32c00cc8e4ed913a63e5c5 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Mon, 6 May 2024 17:30:35 +0200 Subject: [PATCH] Start implementing a logger --- api/v1/environments.go | 4 ++-- main.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api/v1/environments.go b/api/v1/environments.go index 438fb2f..b6a69e6 100644 --- a/api/v1/environments.go +++ b/api/v1/environments.go @@ -192,8 +192,8 @@ func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*pr } func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environments_ListServer) error { - log := e.logInstance - log.WithValues("user_id", in.GetOwnerId().GetUuid()) + logInstance := e.logInstance + log := logInstance.WithValues("user_id", in.GetOwnerId().GetUuid()) ctx := logr.NewContext(stream.Context(), log) environment := &controllers.Environemnt{ diff --git a/main.go b/main.go index 286c9b6..f941fdd 100644 --- a/main.go +++ b/main.go @@ -52,11 +52,6 @@ func main() { func server(params Serve) error { // Make sure the download dir exists - if err := os.MkdirAll(params.DownloadDir, 0777); err != nil { - return err - } - - // Init a logger var log logr.Logger zapLog, err := zap.NewDevelopment() @@ -64,10 +59,17 @@ func server(params Serve) error { panic(fmt.Sprintf("who watches the watchmen (%v)?", err)) } log = zapr.NewLogger(zapLog) - log.Info("enabled") + + if err := os.MkdirAll(params.DownloadDir, 0777); err != nil { + log.Error(err, "Coulnd't create a download dir") + return err + } + + // Init a logger controller, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{}) if err != nil { + log.Error(err, "Coulnd't start a kube manager") return err }