logrus

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2022 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Example
package main

import (
	"log"

	"github.com/sirupsen/logrus"

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

func main() {
	// Export `AXIOM_TOKEN`, `AXIOM_ORG_ID` (when using a personal token) and
	// `AXIOM_DATASET` for Axiom Cloud.
	// Export `AXIOM_URL`, `AXIOM_TOKEN` and `AXIOM_DATASET` for Axiom Selfhost.

	hook, err := adapter.New()
	if err != nil {
		log.Fatal(err)
	}
	logrus.RegisterExitHandler(hook.Close)

	logger := logrus.New()
	logger.AddHook(hook)

	logger.WithField("mood", "hyped").Info("This is awesome!")
	logger.WithField("mood", "worried").Warn("This is no that awesome...")
	logger.WithField("mood", "depressed").Error("This is rather bad.")

	logrus.Exit(0)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrMissingDatasetName = errors.New("missing dataset name")

ErrMissingDatasetName is raised when a dataset name is not provided. Set it manually using the SetDataset option or export `AXIOM_DATASET`.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook implements a `logrus.Hook` used for shipping logs to Axiom.

func New

func New(options ...Option) (*Hook, error)

New creates a new `Hook` configured to ingest logs to the Axiom deployment and dataset as specified by the environment. Refer to `axiom.NewClient()` for more details on how configuring the Axiom deployment works or pass the `SetClient()` option to pass a custom client or `SetClientOptions()` to control the Axiom client creation. To specify the dataset set `AXIOM_DATASET` or use the `SetDataset()` option.

An API token with `axiom.CanIngest` permission is sufficient enough.

Additional options can be supplied to configure the `Hook`.

A hook needs to be closed properly to make sure all logs are sent by calling `Close()`.

func (*Hook) Close

func (h *Hook) Close()

Close the hook and make sure all events are flushed. This should be registered with `logrus.RegisterExitHandler(h.Close)`. Closing the hook renders it unusable for further use.

func (*Hook) Fire

func (h *Hook) Fire(entry *logrus.Entry) error

Fire implements `logrus.Hook`.

func (*Hook) Levels

func (h *Hook) Levels() []logrus.Level

Levels implements `logrus.Hook`.

type Option

type Option func(*Hook) error

An Option modifies the behaviour of the Axiom hook.

func SetClient added in v0.4.0

func SetClient(client *axiom.Client) Option

SetClient specifies the Axiom client to use for ingesting the logs.

func SetClientOptions added in v0.4.0

func SetClientOptions(options ...axiom.Option) Option

SetClientOptions specifies the Axiom client options to pass to `axiom.NewClient()`. `axiom.NewClient()` is only called if no client was specified by the `SetClient` option.

func SetDataset added in v0.4.0

func SetDataset(datasetName string) Option

SetDataset specifies the dataset to ingest the logs into. Can also be specified using the `AXIOM_DATASET` environment variable.

func SetIngestOptions added in v0.4.0

func SetIngestOptions(opts axiom.IngestOptions) Option

SetIngestOptions specifies the ingestion options to use for ingesting the logs.

func SetLevels added in v0.4.0

func SetLevels(levels ...logrus.Level) Option

SetLevels sets the logrus levels that the Axiom hook will create log entries for.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL