Backend: Error Monitoring
Backend: Logging
Go
JS
Python
Ruby
Java
Rust
Hosting Providers
Backend: Tracing
Native OpenTelemetry
Fullstack Frameworks
Overview
Self Host & Local Dev
Menu
Logging in Go / Logrus
Learn how to set up highlight.io Go log ingestion with logrus.
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(ctx).WithField("user", "bob").Infof("hello, %s!", "world")
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-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 highlight.io")
// send logs with a string message severity
lvl, _ := logrus.ParseLevel("warn")
logrus.WithContext(ctx).Log(lvl, "whoa there")
}
4
Verify your backend logs are being recorded.
Visit the highlight logs portal and check that backend logs are coming in.