Skip to content

andyfusniak/stackdriver-gae-logrus-plugin

Repository files navigation

Stackdriver GAE Logrus Plugin

Logrus is a structured logger for Go compatible with the standard library logger.

Stackdriver GAE Logrus Plugin is a lightweight plugin providing threaded message entries on Google Cloud Run and Google App Engine (GAE) Standard Environment.

Cloud Run and GAE adds a request header X-Cloud-Trace-Context to HTTP requests. middleware.XCloudTraceContext provides an HTTP Middleware component that parses this header and make it available in the context.

contextLogger := log.WithContext(r.Context())

contextLogger.WithFields(log.Fields{
	"battery": "50",
}).Debug("Flux capacitor low")

contextLogger.WithFields(log.Fields{
	"status": "busted",
}).Info("Warp speed activated")

contextLogger.WithFields(log.Fields{
	"status": "hmmm",
}).Warn("You have been warning")

contextLogger.WithFields(log.Fields{
	"status": "busted",
}).Error("These are not the drones you are looking for")

In the Stack Driver Logging Cloud Console you can filter results by request.

Filter results by request

Opening an individual request will show each log entry nested within. Each entry will have a color coded icon showing its severity corrsponding to its nearest equivilent Logrus level.

Whilst debugging select any individual log message's trace value and click "Show matching entries".

This will automatically set the filters to reveal all log entries associated to that HTTP request.

Clicking the discover icon expands the log entry to reveal the jsonPayload section. jsonPayload.data contains the field data set using the standard Logrus WithFields method.

contextLogger.WithFields(log.Fields{
	"status": "busted",
}).Error("These are not the drones you are looking for")

To run the example locally use:

make run

Windows

If you do not have Make installed.

go run ./examples/http-service/main.go

About

Structured threaded log entries for GAE Standard Environment for the Go programming language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published