Why does calling log.Infof() from google.golang.org/appengine/log produce the error /logservice.Flush is not registered?
When I use log.Infof() to output logs in App Engine, I get the following error:
internal.flushLog: Flush RPC: Call error 1: call /logservice.Flush is not registered
I ran into the same issue when running App Engine code outside the actual App Engine environment, like on my local machine or in unit tests.
The google.golang.org/appengine/log package relies on App Engine’s internal /logservice.Flush RPC, which only exists when the code is running in the App Engine standard environment.
If you’re testing locally or running outside App Engine, that’s why you see:
/logservice.Flush is not registered
Solution: Use the log package from the standard library (log.Printf, log.Infof) for local development, or use the App Engine aelog package in tests. When deployed, log.Infof works correctly.
This happens because log.Infof from google.golang.org/appengine/log only works when your context (context.Context) is an App Engine request context.
For example:
ctx := appengine.NewContext(r) // from an http.Request
log.Infof(ctx, "Hello world")
If you call it with a context.Background() or outside a request handler, the underlying log service isn’t registered, so Flush fails.
So make sure you always pass a proper App Engine context.
I hit this when trying to run App Engine logging in tests or cron jobs outside the server environment.
The /logservice.Flush is not registered error basically says, “the App Engine internal logging service isn’t available.”
You have a few options:
Use log.Printf for local/dev/test logging.
Wrap your log calls in a helper that checks if the App Engine log service is available.
For testing, use the aetest package to create a test App Engine context:
inst, _ := aetest.NewInstance(nil)
ctx, done, _ := inst.NewContext()
defer done()
log.Infof(ctx, "Test log") // works inside test context
This ensures log.Infof won’t panic or produce the Flush error.