Documentation ¶
Overview ¶
Example ¶
package main import ( "context" "net/http" "os" "github.com/vvakame/sdlog/aelog" ) func main() { _ = os.Setenv("GAE_APPLICATION", "example") r, err := http.NewRequest("GET", "/", nil) if err != nil { panic(err) } // mimic AppEngine environment's request r.Header.Add("X-Cloud-Trace-Context", "e5e6be3a33c969fc2c696daf9d969fd9/4901377287092830619;o=1") // in your app... ctx := context.Background() ctx = aelog.WithHTTPRequest(ctx, r) aelog.Debugf(ctx, "appengine compat log: %s", "💕 AppEngine") }
Output:
Example (WithOpenCensus) ¶
package main import ( "context" "os" "github.com/vvakame/sdlog/aelog" "go.opencensus.io/trace" ) func main() { _ = os.Setenv("GAE_APPLICATION", "example") // in your app... ctx := context.Background() ctx, span := trace.StartSpan(ctx, "foobar") defer span.End() aelog.Debugf(ctx, "appengine compat log: %s", "💕 AppEngine") }
Output:
Example (WithRecover) ¶
package main import ( "context" "fmt" "net/http" "os" "runtime/debug" "github.com/vvakame/sdlog/aelog" "go.opencensus.io/trace" ) func main() { _ = os.Setenv("GAE_APPLICATION", "example") // in your app... ctx := context.Background() ctx, span := trace.StartSpan(ctx, "foobar") defer span.End() defer func() { err := recover() if err != nil { // not perfect... but better. aelog.Errorf(ctx, "%s\n\n%s", err, string(debug.Stack())) panic(err) } }() var obj *http.Request // boom!! fmt.Println(obj.URL.String()) }
Output:
Index ¶
- Variables
- func Criticalf(ctx context.Context, format string, args ...interface{})
- func Debugf(ctx context.Context, format string, args ...interface{})
- func Errorf(ctx context.Context, format string, args ...interface{})
- func Infof(ctx context.Context, format string, args ...interface{})
- func Warningf(ctx context.Context, format string, args ...interface{})
- func WithHTTPRequest(ctx context.Context, r *http.Request) context.Context
- func WithSourceLocationSkip(ctx context.Context, skip int) context.Context
- type AppEngineConfigurator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LogWriter = func(ctx context.Context, logEntry *buildlog.LogEntry) { b, err := json.Marshal(logEntry) if err != nil { panic(err) } fmt.Println(string(b)) }
LogWriter use write log entry to somewhere. default is stdout.
Functions ¶
func Debugf ¶
Debugf formats its arguments according to the format, analogous to fmt.Printf, and records the text as a log message at Debug level. The message will be associated with the request linked with the provided context.
func WithHTTPRequest ¶
WithHTTPRequest is required when you don't use OpenCensus.
Types ¶
type AppEngineConfigurator ¶
type AppEngineConfigurator struct{}
AppEngineConfigurator works on AppEngine.
func (*AppEngineConfigurator) ProjectID ¶
func (*AppEngineConfigurator) ProjectID() string
ProjectID returns current GCP project id.
Click to show internal directories.
Click to hide internal directories.