func (f *Formatter) Format(e *logrus.Entry) ([]byte, error) {
	ee := entry{
		Severity: levToSev[e.Level],
		Message:  e.Message,
		Data:     e.Data,
	}
	xctc := middleware.XCTC(e.Context)
	if xctc != "" {
		traceID, spanID := parseXCloudTraceContext(string(xctc))
		if traceID != "" && spanID != "" {
			ee.Trace = fmt.Sprintf("projects/%s/traces/%s", f.projectID, traceID)
			ee.SpanID = spanID
		}
	}
	b, err := json.Marshal(ee)
	if err != nil {
		return nil, err
	}
	return append(b, '\n'), nil
}
Format formats a logrus entry in Stackdriver format.
package stackdriver
import (
	"encoding/json"
	"fmt"
	"strings"
	"github.com/andyfusniak/stackdriver-gae-logrus-plugin/middleware"
	"github.com/sirupsen/logrus"
)
const (
	lsDEFAULT   = "DEFAULT"
	lsDEBUG     = "DEBUG"
	lsINFO      = "INFO"
	lsNOTICE    = "NOTICE"
	lsWARNING   = "WARNING"
	lsERROR     = "ERROR"
	lsCRITICAL  = "CRITICAL"
	lsALERT     = "ALERT"
	lsEMERGENCY = "EMERGENCY"
)
var levToSev = map[logrus.Level]string{
	logrus.TraceLevel: lsDEFAULT,
	logrus.DebugLevel: lsDEBUG,
	logrus.InfoLevel:  lsINFO,
	logrus.WarnLevel:  lsWARNING,
	logrus.ErrorLevel: lsERROR,
	logrus.FatalLevel: lsCRITICAL,
	logrus.PanicLevel: lsEMERGENCY,
}
type Formatter struct {
	projectID string
}
type entry struct {
	Trace string `json:"logging.googleapis.com/trace,omitempty"`
	SpanID string `json:"logging.googleapis.com/spanId,omitempty"`
	Data     logrus.Fields `json:"data"`
	Message  string        `json:"message,omitempty"`
	Severity string        `json:"severity,omitempty"`
}
func GAEStandardFormatter(options ...Option) *Formatter {
	fmtr := Formatter{}
	for _, option := range options {
		option(&fmtr)
	}
	return &fmtr
}
func parseXCloudTraceContext(t string) (traceID, spanID string) {
	if t == "" {
		return "", ""
	}
	if len(t) < 34 {
		return "", ""
	}
	if t[32] != '/' {
		return "", ""
	}
	last := strings.LastIndex(t, ";")
	if last == -1 {
		return t[0:32], t[33:]
	}
	return t[0:32], t[33:last]
}
type Option func(*Formatter)
func WithProjectID(pid string) Option {
	return func(f *Formatter) {
		f.projectID = pid
	}
}
type XCTContext string