Skip to content

Commit

Permalink
fix: remove obsolete blank prints (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
anniefu authored Aug 5, 2022
1 parent 3cab285 commit 5c7091f
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions funcframework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -168,12 +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.
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
Expand All @@ -185,12 +179,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))
Expand Down Expand Up @@ -295,13 +283,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)
Expand Down

0 comments on commit 5c7091f

Please sign in to comment.