Start implementing a logger

This commit is contained in:
Nikolai Rodionov 2024-05-06 17:30:35 +02:00
parent 40fd1d5300
commit 557b4dce44
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
2 changed files with 10 additions and 8 deletions

View File

@ -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 { func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environments_ListServer) error {
log := e.logInstance logInstance := e.logInstance
log.WithValues("user_id", in.GetOwnerId().GetUuid()) log := logInstance.WithValues("user_id", in.GetOwnerId().GetUuid())
ctx := logr.NewContext(stream.Context(), log) ctx := logr.NewContext(stream.Context(), log)
environment := &controllers.Environemnt{ environment := &controllers.Environemnt{

14
main.go
View File

@ -52,11 +52,6 @@ func main() {
func server(params Serve) error { func server(params Serve) error {
// Make sure the download dir exists // Make sure the download dir exists
if err := os.MkdirAll(params.DownloadDir, 0777); err != nil {
return err
}
// Init a logger
var log logr.Logger var log logr.Logger
zapLog, err := zap.NewDevelopment() zapLog, err := zap.NewDevelopment()
@ -64,10 +59,17 @@ func server(params Serve) error {
panic(fmt.Sprintf("who watches the watchmen (%v)?", err)) panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
} }
log = zapr.NewLogger(zapLog) 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{}) controller, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
if err != nil { if err != nil {
log.Error(err, "Coulnd't start a kube manager")
return err return err
} }