Documentation
¶
Overview ¶
Package zerolog provides an adapter for the popular github.com/rs/zerolog logging library.
Example ¶
package main import ( "io" "log" "os" "github.com/rs/zerolog" l "github.com/rs/zerolog/log" adapter "github.com/axiomhq/axiom-go/adapters/zerolog" ) func main() { // Export "AXIOM_DATASET" in addition to the required environment variables. writer, err := adapter.New() if err != nil { log.Fatal(err) } l.Logger = zerolog.New(io.MultiWriter(writer, os.Stderr)).With().Timestamp().Logger() l.Logger.Info().Str("mood", "hyped").Msg("This is awesome!") l.Logger.Warn().Str("mood", "worried").Msg("This is no that awesome...") l.Logger.Error().Str("mood", "depressed").Msg("This is rather bad.") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingDataset is raised when a dataset name is not provided. Set it // manually using the [SetDataset] option or export "AXIOM_DATASET". ErrMissingDataset = errors.New("missing dataset name") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Writer)
Option configures axiom events writer.
func SetClientOptions ¶
SetClientOptions configures the axiom client options.
func SetDataset ¶
SetDataset configures the axiom dataset name.
func SetIngestOptions ¶
SetIngestOptions configures the axiom ingest options.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a axiom events writer with std io.Writer interface.
func New ¶
New creates a new Writer 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 Writer needs to be closed properly to make sure all logs are sent by calling Writer.Close.