runtime: Fix global logger configuration.

We used to configure the global logger inside rt.Init(), but that is too
late, since the runtime factories can call the global logger before
rt.Init() is called.

In particular, the internal.HasPublicIP function runs before rt.Init(),
and calls the global logger.

The safest thing seems to be to configure the global logger immediately
after parsing flags, as implemented in this CL.

Change-Id: I8a316fb4c642f81a1e1ee2c3d5b9af1e3ee90923
diff --git a/runtime/factories/chrome/chrome.go b/runtime/factories/chrome/chrome.go
index c34ceae..07cb080 100644
--- a/runtime/factories/chrome/chrome.go
+++ b/runtime/factories/chrome/chrome.go
@@ -34,7 +34,7 @@
 }
 
 func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
-	if err := internal.ParseFlags(commonFlags); err != nil {
+	if err := internal.ParseFlagsAndConfigureGlobalLogger(commonFlags); err != nil {
 		return nil, nil, nil, err
 	}
 
diff --git a/runtime/factories/fake/fake.go b/runtime/factories/fake/fake.go
index 06d139b..f56e40a 100644
--- a/runtime/factories/fake/fake.go
+++ b/runtime/factories/fake/fake.go
@@ -15,6 +15,7 @@
 	"v.io/v23/context"
 	"v.io/v23/rpc"
 
+	"v.io/x/ref/runtime/internal"
 	_ "v.io/x/ref/runtime/internal/flow/protocols/tcp"
 	_ "v.io/x/ref/runtime/internal/flow/protocols/ws"
 	_ "v.io/x/ref/runtime/internal/flow/protocols/wsh"
@@ -41,6 +42,10 @@
 }
 
 func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
+	if err := internal.ConfigureGlobalLoggerFromFlags(); err != nil {
+		return nil, nil, nil, err
+	}
+
 	runtimeInfo.mu.Lock()
 	defer runtimeInfo.mu.Unlock()
 	if runtimeInfo.runtime != nil {
diff --git a/runtime/factories/fake/runtime.go b/runtime/factories/fake/runtime.go
index 1abdae7..8cb7fec 100644
--- a/runtime/factories/fake/runtime.go
+++ b/runtime/factories/fake/runtime.go
@@ -36,11 +36,6 @@
 }
 
 func (r *Runtime) Init(ctx *context.T) error {
-	// nologcall
-	err := logger.Manager(ctx).ConfigureFromFlags()
-	if err != nil && !logger.IsAlreadyConfiguredError(err) {
-		return err
-	}
 	return nil
 }
 
diff --git a/runtime/factories/gce/gce.go b/runtime/factories/gce/gce.go
index 584c823..226449b 100644
--- a/runtime/factories/gce/gce.go
+++ b/runtime/factories/gce/gce.go
@@ -43,12 +43,12 @@
 }
 
 func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
-	if !gce.RunningOnGCE() {
-		return nil, nil, nil, fmt.Errorf("GCE profile used on a non-GCE system")
+	if err := internal.ParseFlagsAndConfigureGlobalLogger(commonFlags); err != nil {
+		return nil, nil, nil, err
 	}
 
-	if err := internal.ParseFlags(commonFlags); err != nil {
-		return nil, nil, nil, err
+	if !gce.RunningOnGCE() {
+		return nil, nil, nil, fmt.Errorf("GCE profile used on a non-GCE system")
 	}
 
 	ac := appcycle.New()
diff --git a/runtime/factories/generic/generic.go b/runtime/factories/generic/generic.go
index 61d58c6..d3a0ac9 100644
--- a/runtime/factories/generic/generic.go
+++ b/runtime/factories/generic/generic.go
@@ -38,7 +38,7 @@
 }
 
 func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
-	if err := internal.ParseFlags(commonFlags); err != nil {
+	if err := internal.ParseFlagsAndConfigureGlobalLogger(commonFlags); err != nil {
 		return nil, nil, nil, err
 	}
 
diff --git a/runtime/factories/roaming/roaming.go b/runtime/factories/roaming/roaming.go
index aca495d..b5f17c6 100644
--- a/runtime/factories/roaming/roaming.go
+++ b/runtime/factories/roaming/roaming.go
@@ -58,7 +58,7 @@
 }
 
 func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
-	if err := internal.ParseFlags(commonFlags); err != nil {
+	if err := internal.ParseFlagsAndConfigureGlobalLogger(commonFlags); err != nil {
 		return nil, nil, nil, err
 	}
 
diff --git a/runtime/factories/static/static.go b/runtime/factories/static/static.go
index 9037f73..b04f6f8 100644
--- a/runtime/factories/static/static.go
+++ b/runtime/factories/static/static.go
@@ -41,7 +41,7 @@
 }
 
 func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
-	if err := internal.ParseFlags(commonFlags); err != nil {
+	if err := internal.ParseFlagsAndConfigureGlobalLogger(commonFlags); err != nil {
 		return nil, nil, nil, err
 	}