Star us on GitHub
Star
Menu

Logging in Go / Fiber

Learn how to set up highlight.io Go log ingestion with fiber.
1
Set up your frontend highlight.io integration.

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

2
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(c.Context()).WithField("user", "bob").Infof("hello, %s!", "world")
Copy
3
Call the Highlight logging SDK.

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

package main import ( "context" "github.com/highlight/highlight/sdk/highlight-go" "github.com/highlight/highlight/sdk/highlight-go/log" "github.com/sirupsen/logrus" ) func main() { // setup the highlight SDK highlight.SetProjectID("<YOUR_PROJECT_ID>") highlight.Start( highlight.WithServiceName("my-fiber-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() app := fiber.New() app.Use(logger.New()) // setup go fiber to use the highlight middleware for header parsing app.Use(highlightFiber.Middleware()) app.Get("/", func(c *fiber.Ctx) error { // in handlers, use logrus with the UserContext to associate logs with the frontend session. logrus.WithContext(c.Context()).Infof("hello from highlight.io") return c.SendString("Hello, World!") }) logrus.Fatal(app.Listen(":3456")) }
Copy
4
Verify your backend logs are being recorded.

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