Documentation ¶
Overview ¶
Package zap provides an adapter for the popular github.com/uber-go/zap logging library.
Example ¶
package main import ( "log" "go.uber.org/zap" adapter "github.com/axiomhq/axiom-go/adapters/zap" ) func main() { // Export `AXIOM_DATASET` in addition to the required environment variables. core, err := adapter.New() if err != nil { log.Fatal(err) } logger := zap.New(core) defer func() { if syncErr := logger.Sync(); syncErr != nil { log.Fatal(syncErr) } }() logger.Info("This is awesome!", zap.String("mood", "hyped")) logger.Warn("This is no that awesome...", zap.String("mood", "worried")) logger.Error("This is rather bad.", zap.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 ¶
func New ¶
New creates a new `zapcore.Core` 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 `ingest` permission is sufficient enough.
Additional options can be supplied to configure the `zapcore.Core`.
Types ¶
type Option ¶
type Option func(*WriteSyncer) error
An Option modifies the behaviour of the Axiom WriteSyncer.
func SetClient ¶ added in v0.4.0
SetClient specifies the Axiom client to use for ingesting the logs.
func SetClientOptions ¶ added in v0.4.0
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
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
SetIngestOptions specifies the ingestion options to use for ingesting the logs.
func SetLevelEnabler ¶ added in v0.4.0
func SetLevelEnabler(levelEnabler zapcore.LevelEnabler) Option
SetLevelEnabler sets the level enabler that the Axiom WriteSyncer will us to determine if logs will be shipped to Axiom.
type WriteSyncer ¶
type WriteSyncer struct {
// contains filtered or unexported fields
}
WriteSyncer implements a `zapcore.WriteSyncer` used for shipping logs to Axiom.
func (*WriteSyncer) Sync ¶
func (ws *WriteSyncer) Sync() error
Sync implements `zapcore.WriteSyncer`.