cloud/log: move cloud logging package from core repo

Change-Id: I5eb0c881bf9c496059ec8ff2f680a293ccf59c7c
Reviewed-on: https://upspin-review.googlesource.com/9302
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/cloud/log/log.go b/cloud/log/log.go
new file mode 100644
index 0000000..686cf04
--- /dev/null
+++ b/cloud/log/log.go
@@ -0,0 +1,52 @@
+// Copyright 2017 The Upspin Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package log provides an implemention of upspin.io/log.ExternalLogger that
+// sends logs to the Google Cloud Logging service.
+package log // import "gcp.upspin.io/cloud/log"
+
+import (
+	"context"
+
+	"upspin.io/log"
+
+	"cloud.google.com/go/logging"
+	"google.golang.org/api/option"
+)
+
+// Connect creates a logger that speaks to the Google Cloud Logging service for
+// the given project and registers that logger with the log package.
+func Connect(projectID, logName string) error {
+	var err error
+	client, err := logging.NewClient(context.Background(), projectID, option.WithScopes(logging.WriteScope))
+	if err != nil {
+		return err
+	}
+	log.Register(logger{
+		cloud: client.Logger(logName),
+	})
+	return nil
+}
+
+type logger struct {
+	cloud *logging.Logger
+}
+
+var severity = map[log.Level]logging.Severity{
+	log.DebugLevel: logging.Debug,
+	log.ErrorLevel: logging.Error,
+	log.InfoLevel:  logging.Info,
+}
+
+func (l logger) Log(level log.Level, message string) {
+	s, ok := severity[level]
+	if !ok {
+		return
+	}
+	l.cloud.StandardLogger(s).Print(message)
+}
+
+func (l logger) Flush() {
+	l.cloud.Flush()
+}
diff --git a/cmd/dirserver-gcp/main.go b/cmd/dirserver-gcp/main.go
index bb188a6..d835b77 100644
--- a/cmd/dirserver-gcp/main.go
+++ b/cmd/dirserver-gcp/main.go
@@ -8,7 +8,7 @@
 package main // import "gcp.upspin.io/cmd/dirserver-gcp"
 
 import (
-	cloudLog "upspin.io/cloud/log"
+	cloudLog "gcp.upspin.io/cloud/log"
 	"upspin.io/flags"
 	"upspin.io/log"
 	"upspin.io/metric"
diff --git a/cmd/keyserver-gcp/main.go b/cmd/keyserver-gcp/main.go
index 99f8d55..a8c0551 100644
--- a/cmd/keyserver-gcp/main.go
+++ b/cmd/keyserver-gcp/main.go
@@ -10,7 +10,7 @@
 	"flag"
 	"net"
 
-	cloudLog "upspin.io/cloud/log"
+	cloudLog "gcp.upspin.io/cloud/log"
 	"upspin.io/factotum"
 	"upspin.io/flags"
 	"upspin.io/log"
diff --git a/cmd/storeserver-gcp/main.go b/cmd/storeserver-gcp/main.go
index 07aeb5b..242141b 100644
--- a/cmd/storeserver-gcp/main.go
+++ b/cmd/storeserver-gcp/main.go
@@ -7,7 +7,7 @@
 package main // import "gcp.upspin.io/cmd/storeserver-gcp"
 
 import (
-	cloudLog "upspin.io/cloud/log"
+	cloudLog "gcp.upspin.io/cloud/log"
 	"upspin.io/flags"
 	"upspin.io/log"
 	"upspin.io/metric"