func (lg *Logger) Emergency(v interface{}) {
	lg.Log(logging.Emergency, v)
}
Emergency calls Log with emergency severity.
package gaelog
import (
	"fmt"
	"log"
	"net/http"
	"os"
	"strings"
	"time"
	"cloud.google.com/go/logging"
	"google.golang.org/genproto/googleapis/api/monitoredres"
)
const (
	DefaultLogID = "app_log"
	traceContextHeaderName = "X-Cloud-Trace-Context"
)
func traceID(projectID, trace string) string {
	return fmt.Sprintf("projects/%s/traces/%s", projectID, trace)
}
type envVarError struct {
	varName string
}
func (e *envVarError) Error() string {
	return fmt.Sprintf("gaelog: %s env var is not set, falling back to standard library log", e.varName)
}
type Logger struct {
	client *logging.Client
	logger *logging.Logger
	monRes *monitoredres.MonitoredResource
	trace  string
}
func NewWithID(r *http.Request, logID string, options ...logging.LoggerOption) (*Logger, error) {
	projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
	if projectID == "" {
		return &Logger{}, &envVarError{"GOOGLE_CLOUD_PROJECT"}
	}
	serviceID := os.Getenv("GAE_SERVICE")
	if serviceID == "" {
		return &Logger{}, &envVarError{"GAE_SERVICE"}
	}
	versionID := os.Getenv("GAE_VERSION")
	if versionID == "" {
		return &Logger{}, &envVarError{"GAE_VERSION"}
	}
	traceContext := r.Header.Get(traceContextHeaderName)
	if traceContext == "" {
		return &Logger{}, fmt.Errorf("gaelog: %s header is not set, falling back to standard library log", traceContextHeaderName)
	}
	client, err := logging.NewClient(r.Context(), fmt.Sprintf("projects/%s", projectID))
	if err != nil {
		return &Logger{}, err
	}
	monRes := &monitoredres.MonitoredResource{
		Labels: map[string]string{
			"module_id":  serviceID,
			"project_id": projectID,
			"version_id": versionID,
		},
		Type: "gae_app",
	}
	return &Logger{
		client: client,
		logger: client.Logger(logID, options...),
		monRes: monRes,
		trace:  traceID(projectID, strings.Split(traceContext, "/")[0]),
	}, nil
}
func New(r *http.Request, options ...logging.LoggerOption) (*Logger, error) {
	return NewWithID(r, DefaultLogID, options...)
}
func (lg *Logger) Close() error {
	if lg.client != nil {
		return lg.client.Close()
	}
	return nil
}
func (lg *Logger) Logf(severity logging.Severity, format string, v ...interface{}) {
	if lg.logger == nil {
		log.Printf(format, v...)
		return
	}
	lg.logger.Log(logging.Entry{
		Timestamp: time.Now(),
		Severity:  severity,
		Payload:   fmt.Sprintf(format, v...),
		Trace:     lg.trace,
		Resource:  lg.monRes,
	})
}
func (lg *Logger) Debugf(format string, v ...interface{}) {
	lg.Logf(logging.Debug, format, v...)
}
func (lg *Logger) Infof(format string, v ...interface{}) {
	lg.Logf(logging.Info, format, v...)
}
func (lg *Logger) Noticef(format string, v ...interface{}) {
	lg.Logf(logging.Notice, format, v...)
}
func (lg *Logger) Warningf(format string, v ...interface{}) {
	lg.Logf(logging.Warning, format, v...)
}
func (lg *Logger) Errorf(format string, v ...interface{}) {
	lg.Logf(logging.Error, format, v...)
}
func (lg *Logger) Criticalf(format string, v ...interface{}) {
	lg.Logf(logging.Critical, format, v...)
}
func (lg *Logger) Alertf(format string, v ...interface{}) {
	lg.Logf(logging.Alert, format, v...)
}
func (lg *Logger) Emergencyf(format string, v ...interface{}) {
	lg.Logf(logging.Emergency, format, v...)
}
func (lg *Logger) Log(severity logging.Severity, v interface{}) {
	if lg.logger == nil {
		log.Print(v)
		return
	}
	lg.logger.Log(logging.Entry{
		Timestamp: time.Now(),
		Severity:  severity,
		Payload:   v,
		Trace:     lg.trace,
		Resource:  lg.monRes,
	})
}
func (lg *Logger) Debug(v interface{}) {
	lg.Log(logging.Debug, v)
}
func (lg *Logger) Info(v interface{}) {
	lg.Log(logging.Info, v)
}
func (lg *Logger) Notice(v interface{}) {
	lg.Log(logging.Notice, v)
}
func (lg *Logger) Warning(v interface{}) {
	lg.Log(logging.Warning, v)
}
func (lg *Logger) Error(v interface{}) {
	lg.Log(logging.Error, v)
}
func (lg *Logger) Critical(v interface{}) {
	lg.Log(logging.Critical, v)
}
func (lg *Logger) Alert(v interface{}) {
	lg.Log(logging.Alert, v)
}