Star us on GitHub

Logging in Go / Logrus

Learn how to set up Go log ingestion with logrus.
Set up your frontend integration.

First, make sure you've followed the frontend getting started guide.

Call logrus methods while passing the request context.

The request context allows highlight to associate logs with the incoming frontend session and network request.

logrus.WithContext(ctx).WithField("user", "bob").Infof("hello, %s!", "world")
Call the Highlight logging SDK.

Use our SDK to configure logrus, and use it as normal.

package main import ( "context" "" "" "" ) func main() { // setup the highlight SDK highlight.SetProjectID("<YOUR_PROJECT_ID>") highlight.Start( highlight.WithServiceName("my-app"), highlight.WithServiceVersion("git-sha"), ) defer highlight.Stop() // setup highlight logrus hook hlog.Init() // if you don't want to get stdout / stderr output, add the following uncommented // hlog.DisableOutput() // if in a request, provide context to associate logs with frontend sessions ctx := context.TODO() // send logs logrus.WithContext(ctx).WithField("hello", "world").Info("welcome to") // send logs with a string message severity lvl, _ := logrus.ParseLevel("warn") logrus.WithContext(ctx).Log(lvl, "whoa there") }
Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.