From 9d37ffb1f325984749b6e768ccf1f57326ee8d48 Mon Sep 17 00:00:00 2001 From: Annie Fu Date: Fri, 5 Aug 2022 10:13:33 -0700 Subject: [PATCH 1/2] fix: remove obsolete blank prints --- funcframework/framework.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/funcframework/framework.go b/funcframework/framework.go index 2959365..b3f4fb0 100644 --- a/funcframework/framework.go +++ b/funcframework/framework.go @@ -140,8 +140,8 @@ func initServer() (*http.ServeMux, error) { func wrapFunction(fn registry.RegisteredFunction) (http.Handler, error) { // Check if we have a function resource set, and if so, log progress. - if os.Getenv("K_SERVICE") == "" { - fmt.Printf("Serving function %s\n", fn.Name) + if os.Getenv("FUNCTION_TARGET") == "" { + fmt.Printf("Serving function: %q", fn.Name) } if fn.HTTPFn != nil { @@ -169,11 +169,7 @@ func wrapFunction(fn registry.RegisteredFunction) (http.Handler, error) { func wrapHTTPFunction(fn func(http.ResponseWriter, *http.Request)) (http.Handler, error) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // TODO(b/111823046): Remove following once Cloud Functions does not need flushing the logs anymore. - if os.Getenv("K_SERVICE") != "" { - // Force flush of logs after every function trigger when running on GCF. - defer fmt.Println() - defer fmt.Fprintln(os.Stderr) - } + defer recoverPanic(w, "user function execution") fn(w, r) }), nil @@ -185,12 +181,6 @@ func wrapEventFunction(fn interface{}) (http.Handler, error) { return nil, err } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if os.Getenv("K_SERVICE") != "" { - // Force flush of logs after every function trigger when running on GCF. - defer fmt.Println() - defer fmt.Fprintln(os.Stderr) - } - if shouldConvertCloudEventToBackgroundRequest(r) { if err := convertCloudEventToBackgroundRequest(r); err != nil { writeHTTPErrorResponse(w, http.StatusBadRequest, crashStatus, fmt.Sprintf("error converting CloudEvent to Background Event: %v", err)) @@ -295,13 +285,6 @@ func writeHTTPErrorResponse(w http.ResponseWriter, statusCode int, status, msg s } fmt.Fprint(os.Stderr, msg) - // Flush stdout and stderr when running on GCF. This must be done before writing - // the HTTP response in order for all logs to appear in Stackdriver. - if os.Getenv("K_SERVICE") != "" { - fmt.Println() - fmt.Fprintln(os.Stderr) - } - w.Header().Set(functionStatusHeader, status) w.WriteHeader(statusCode) fmt.Fprint(w, msg) From 78c6a9b2fd7ca79c95df28ed61df4fb22de8ff4e Mon Sep 17 00:00:00 2001 From: Annie Fu Date: Fri, 5 Aug 2022 14:17:15 -0700 Subject: [PATCH 2/2] Remove outdated comment --- funcframework/framework.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/funcframework/framework.go b/funcframework/framework.go index b3f4fb0..0980a43 100644 --- a/funcframework/framework.go +++ b/funcframework/framework.go @@ -168,8 +168,6 @@ func wrapFunction(fn registry.RegisteredFunction) (http.Handler, error) { func wrapHTTPFunction(fn func(http.ResponseWriter, *http.Request)) (http.Handler, error) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // TODO(b/111823046): Remove following once Cloud Functions does not need flushing the logs anymore. - defer recoverPanic(w, "user function execution") fn(w, r) }), nil