Permalink
Browse files

Comment out gcloud for now due to import not found

  • Loading branch information...
peter-edge committed Dec 3, 2017
1 parent 47898f3 commit 2a810629566a2d0f0d4107df244e8828b9f7bd5c
Showing with 110 additions and 110 deletions.
  1. +16 −16 gcloud/gcloud.go
  2. +33 −33 gcloud/gcloud_test.go
  3. +61 −61 gcloud/pusher.go
View
@@ -3,20 +3,20 @@
// See https://cloud.google.com/logging/docs/ for more details.
package gcloudlion
import (
"go.pedge.io/lion"
"google.golang.org/api/logging/v1beta3"
)
//import (
//"go.pedge.io/lion"
//"google.golang.org/api/logging/v1beta3"
//)
// NewPusher creates a new lion.Pusher that logs using the Google Cloud Logging API.
func NewPusher(
service *logging.ProjectsLogsEntriesService,
projectID string,
logName string,
) lion.Pusher {
return newPusher(
service,
projectID,
logName,
)
}
//// NewPusher creates a new lion.Pusher that logs using the Google Cloud Logging API.
//func NewPusher(
//service *logging.ProjectsLogsEntriesService,
//projectID string,
//logName string,
//) lion.Pusher {
//return newPusher(
//service,
//projectID,
//logName,
//)
//}
View
@@ -1,37 +1,37 @@
package gcloudlion_test
import (
"os"
//import (
//"os"
"go.pedge.io/lion"
"go.pedge.io/lion/gcloud"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/logging/v1beta3"
)
//"go.pedge.io/lion"
//"go.pedge.io/lion/gcloud"
//"golang.org/x/net/context"
//"golang.org/x/oauth2/google"
//"google.golang.org/api/logging/v1beta3"
//)
func Example() {
projectID, _ := os.LookupEnv("GCLOUD_PROJECT_ID")
logName := "lion"
client, err := google.DefaultClient(
context.Background(),
logging.LoggingWriteScope,
)
if err != nil {
lion.Errorln(err)
return
}
service, err := logging.New(client)
if err != nil {
lion.Errorln(err)
return
}
logger := lion.NewLogger(
gcloudlion.NewPusher(
service.Projects.Logs.Entries,
projectID,
logName,
),
)
logger.Infoln("Hello from lion!")
}
//func Example() {
//projectID, _ := os.LookupEnv("GCLOUD_PROJECT_ID")
//logName := "lion"
//client, err := google.DefaultClient(
//context.Background(),
//logging.LoggingWriteScope,
//)
//if err != nil {
//lion.Errorln(err)
//return
//}
//service, err := logging.New(client)
//if err != nil {
//lion.Errorln(err)
//return
//}
//logger := lion.NewLogger(
//gcloudlion.NewPusher(
//service.Projects.Logs.Entries,
//projectID,
//logName,
//),
//)
//logger.Infoln("Hello from lion!")
//}
View
@@ -1,70 +1,70 @@
package gcloudlion
import (
"time"
//import (
//"time"
"go.pedge.io/lion"
"google.golang.org/api/logging/v1beta3"
)
//"go.pedge.io/lion"
//"google.golang.org/api/logging/v1beta3"
//)
const customServiceName = "compute.googleapis.com"
//const customServiceName = "compute.googleapis.com"
var (
// https://cloud.google.com/logging/docs/api/ref/rest/v1beta3/projects.logs.entries/write#LogSeverity
severityName = map[lion.Level]string{
lion.LevelNone: "DEFAULT",
lion.LevelDebug: "DEBUG",
lion.LevelInfo: "INFO",
lion.LevelWarn: "WARNING",
lion.LevelError: "ERROR",
lion.LevelFatal: "ERROR",
lion.LevelPanic: "ALERT",
}
)
//var (
//// https://cloud.google.com/logging/docs/api/ref/rest/v1beta3/projects.logs.entries/write#LogSeverity
//severityName = map[lion.Level]string{
//lion.LevelNone: "DEFAULT",
//lion.LevelDebug: "DEBUG",
//lion.LevelInfo: "INFO",
//lion.LevelWarn: "WARNING",
//lion.LevelError: "ERROR",
//lion.LevelFatal: "ERROR",
//lion.LevelPanic: "ALERT",
//}
//)
type pusher struct {
service *logging.ProjectsLogsEntriesService
projectID string
logName string
}
//type pusher struct {
//service *logging.ProjectsLogsEntriesService
//projectID string
//logName string
//}
func newPusher(
service *logging.ProjectsLogsEntriesService,
projectID string,
logName string,
) *pusher {
return &pusher{
service,
projectID,
logName,
}
}
//func newPusher(
//service *logging.ProjectsLogsEntriesService,
//projectID string,
//logName string,
//) *pusher {
//return &pusher{
//service,
//projectID,
//logName,
//}
//}
func (p *pusher) Push(entry *lion.Entry) error {
id := entry.ID
if id == "" {
id = lion.DefaultIDAllocator.Allocate()
}
_, err := p.service.Write(
p.projectID,
p.logName,
&logging.WriteLogEntriesRequest{
Entries: []*logging.LogEntry{
{
InsertId: id,
StructPayload: entry,
Metadata: &logging.LogEntryMetadata{
ServiceName: customServiceName,
Severity: severityName[entry.Level],
Timestamp: entry.Time.Format(time.RFC3339),
},
},
},
},
).Do()
return err
}
//func (p *pusher) Push(entry *lion.Entry) error {
//id := entry.ID
//if id == "" {
//id = lion.DefaultIDAllocator.Allocate()
//}
//_, err := p.service.Write(
//p.projectID,
//p.logName,
//&logging.WriteLogEntriesRequest{
//Entries: []*logging.LogEntry{
//{
//InsertId: id,
//StructPayload: entry,
//Metadata: &logging.LogEntryMetadata{
//ServiceName: customServiceName,
//Severity: severityName[entry.Level],
//Timestamp: entry.Time.Format(time.RFC3339),
//},
//},
//},
//},
//).Do()
//return err
//}
func (p *pusher) Flush() error {
return nil
}
//func (p *pusher) Flush() error {
//return nil
//}

0 comments on commit 2a81062

Please sign in to comment.