log: don't mirror log to stderr on 2nd gen (#177)
Only duplicate log to stderr if not running on App Engine second generation
diff --git a/appengine.go b/appengine.go
index 7952545..0cca033 100644
--- a/appengine.go
+++ b/appengine.go
@@ -78,6 +78,12 @@
return internal.IsAppEngine()
}
+// IsSecondGen reports whether the App Engine app is running on the second generation
+// runtimes (>= Go 1.11).
+func IsSecondGen() bool {
+ return internal.IsSecondGen()
+}
+
// NewContext returns a context for an in-flight HTTP request.
// This function is cheap.
func NewContext(req *http.Request) context.Context {
diff --git a/internal/api.go b/internal/api.go
index c951495..bbc1cb9 100644
--- a/internal/api.go
+++ b/internal/api.go
@@ -579,7 +579,10 @@
Level: &level,
Message: &s,
})
- log.Print(logLevelName[level] + ": " + s)
+ // Only duplicate log to stderr if not running on App Engine second generation
+ if !IsSecondGen() {
+ log.Print(logLevelName[level] + ": " + s)
+ }
}
// flushLog attempts to flush any pending logs to the appserver.
diff --git a/internal/identity.go b/internal/identity.go
index 6d89d63..9b4134e 100644
--- a/internal/identity.go
+++ b/internal/identity.go
@@ -31,9 +31,15 @@
// ../appengine.go. See that file for commentary.
func IsStandard() bool {
// appengineStandard will be true for first-gen runtimes (<= Go 1.9) but not
- // second-gen (>= Go 1.11). Second-gen runtimes set $GAE_ENV so we use that
- // to check if we're on a second-gen runtime.
- return appengineStandard || os.Getenv("GAE_ENV") == "standard"
+ // second-gen (>= Go 1.11).
+ return appengineStandard || IsSecondGen()
+}
+
+// IsStandard is the implementation of the wrapper function of the same name in
+// ../appengine.go. See that file for commentary.
+func IsSecondGen() bool {
+ // Second-gen runtimes set $GAE_ENV so we use that to check if we're on a second-gen runtime.
+ return os.Getenv("GAE_ENV") == "standard"
}
// IsFlex is the implementation of the wrapper function of the same name in