Use the adapter of the Axiom Go SDK to send logs generated by the sirupsen/logrus library to Axiom.

The Axiom Go SDK is an open-source project and welcomes your contributions. For more information, see the GitHub repository.

Prerequisites

Set up SDK

  1. Install the Axiom Go SDK and configure your environment as explained in Send data from Go app to Axiom.

  2. In your Go app, import the logrus package. It is imported as an adapter so that it doesn’t conflict with the sirupsen/logrus package.

    import adapter "github.com/axiomhq/axiom-go/adapters/logrus"
    

    Alternatively, configure the adapter using options passed to the New function:

    hook, err := adapter.New(
        adapter.SetDataset("DATASET_NAME"),
    )
    

    Replace DATASET_NAME with the name of the Axiom dataset where you want to send data.

Configure client

To configure the underlying client manually, choose one of the following:

  • Use SetClient to pass in the client you have previously created with Send data from Go app to Axiom.

  • Use SetClientOptions to pass client options to the adapter.

    import (
        "github.com/axiomhq/axiom-go/axiom"
        adapter "github.com/axiomhq/axiom-go/adapters/logrus"
    )
    
    // ...
    
    hook, err := adapter.New(
        adapter.SetClientOptions(
            axiom.SetPersonalTokenConfig("AXIOM_TOKEN"),
        ),
    )
    

The adapter uses a buffer to batch events before sending them to Axiom. Flush this buffer explicitly by calling Close. For more information, see the example in GitHub.

Reference

For a full reference of the adapter’s functions, see the Go Packages page.