Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove obsolete blank prints #144

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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