Documentation ¶
Overview ¶
Package slog provides an adapter for the standard libraries structured logging package.
Example ¶
package main import ( "log" "log/slog" adapter "github.com/axiomhq/axiom-go/adapters/slog" ) func main() { // Export "AXIOM_DATASET" in addition to the required environment variables. handler, err := adapter.New() if err != nil { log.Fatal(err.Error()) } defer handler.Close() logger := slog.New(handler) logger.Info("This is awesome!", "mood", "hyped") logger.With("mood", "worried").Warn("This is no that awesome...") logger.Error("This is rather bad.", slog.String("mood", "depressed")) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements a slog.Handler used for shipping logs to Axiom.
func New ¶
New creates a new handler that ingests logs into Axiom. It automatically takes its configuration from the environment. To connect, export the following environment variables:
- AXIOM_TOKEN
- AXIOM_ORG_ID (only when using a personal token)
- AXIOM_DATASET
The configuration can be set manually using options which are prefixed with "Set".
An API token with "ingest" permission is sufficient enough.
A handler needs to be closed properly to make sure all logs are sent by calling Handler.Close.
func (*Handler) Close ¶
func (h *Handler) Close()
Close the handler and make sure all events are flushed. Closing the handler renders it unusable for further use.
func (*Handler) Enabled ¶
Enabled implements slog.Handler.
func (*Handler) Handle ¶
Handle implements slog.Handler.
func (*Handler) WithAttrs ¶
WithAttrs implements slog.Handler.
type Option ¶
An Option modifies the behaviour of the Axiom handler.
func SetClientOptions ¶
SetClientOptions specifies the Axiom client options to pass to axiom.NewClient which is only called if no axiom.Client was specified by the SetClient option.
func SetDataset ¶
SetDataset specifies the dataset to ingest the logs into. Can also be specified using the "AXIOM_DATASET" environment variable.
func SetIngestOptions ¶
SetIngestOptions specifies the ingestion options to use for ingesting the logs.