From 2f05228b0f8fe39d20620185195886f269d0ccb0 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Mon, 27 May 2024 18:38:10 +0200 Subject: [PATCH] Fix controller runtime logger setup --- go.mod | 2 +- go.sum | 2 -- main.go | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 544723c..207c25d 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/deepmap/oapi-codegen v1.16.2 github.com/deepmap/oapi-codegen/v2 v2.1.0 github.com/getkin/kin-openapi v0.123.0 + github.com/go-logr/logr v1.4.2 github.com/hashicorp/golang-lru v1.0.2 github.com/labstack/echo/v4 v4.12.0 github.com/oapi-codegen/runtime v1.1.1 @@ -35,7 +36,6 @@ require ( github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/fatih/color v1.17.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-logr/logr v1.4.2 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect diff --git a/go.sum b/go.sum index 23ddc84..07cc8e8 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/projectsyn/lieutenant-operator v1.5.3 h1:n2gIWvws+hy5WxbcgiW5Pf3lNbcsrEC6vL9DBzp1Ves= -github.com/projectsyn/lieutenant-operator v1.5.3/go.mod h1:JIIxR4epvsV57V1nb+f1yIFZ4wQJAgvpnkCrmY/xowA= github.com/projectsyn/lieutenant-operator v1.6.0 h1:9ACzJjjBAonAGu5SkaPMzfZ9e94vJq663BPic1Vq55c= github.com/projectsyn/lieutenant-operator v1.6.0/go.mod h1:JIIxR4epvsV57V1nb+f1yIFZ4wQJAgvpnkCrmY/xowA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= diff --git a/main.go b/main.go index f0ab5c7..2d89d85 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,10 @@ import ( "os" _ "github.com/cosmtrek/air/runner" // used for hot reload + "github.com/go-logr/logr" + "github.com/go-logr/logr/funcr" "github.com/projectsyn/lieutenant-api/pkg/service" + crlog "sigs.k8s.io/controller-runtime/pkg/log" ) // Version is the lieutenant-api version (set during build) @@ -17,6 +20,8 @@ var ( ) func main() { + crlog.SetLogger(newStdoutLogger()) + conf := service.APIConfig{ APIVersion: Version, Namespace: os.Getenv("NAMESPACE"), @@ -34,3 +39,13 @@ func main() { e.Logger.Fatal(e.Start(":8080")) } + +func newStdoutLogger() logr.Logger { + return funcr.New(func(prefix, args string) { + if prefix != "" { + fmt.Printf("%s: %s\n", prefix, args) + } else { + fmt.Println(args) + } + }, funcr.Options{}) +}