loki

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package loki is a logging sink that pushes records to Grafana Loki:

loki.New(loki.Options{URL: "http://localhost:3100", Labels: map[string]string{"app": "shop"}})

Each record is a JSON line in a stream with the sink's labels and the record's level. Unset options come from LOKI_URL, LOKI_USERNAME, LOKI_PASSWORD and LOKI_TENANT_ID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// URL is Loki's address, such as http://localhost:3100; the push path
	// is added. The default is LOKI_URL's, or http://localhost:3100.
	URL string
	// Labels are every stream's labels. Keep them few and their values
	// fixed: Loki indexes streams by them. The default is service, the
	// program's name. "level" is added for each record.
	Labels map[string]string
	// Username and Password are sent as basic authentication, as Grafana
	// Cloud wants them.
	Username, Password string
	// TenantID is sent as X-Scope-OrgID, for multi-tenant Loki.
	TenantID string
	// Metadata names top-level attributes sent as structured metadata
	// (Loki 3 and newer) as well as in the line, such as
	// logging.RequestIDKey or logging.TraceIDKey.
	Metadata []string
	// NoGzip sends requests uncompressed.
	NoGzip bool
	// Client sends the requests. The default is http.DefaultClient.
	Client *http.Client
}

Options configures the sink.

type Sink

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

Sink pushes to Loki. Make one with New.

func New

func New(o Options) *Sink

New returns a Loki sink.

func (*Sink) Export

func (s *Sink) Export(ctx context.Context, entries []logging.Entry) error

Export implements logging.Sink.

func (*Sink) Name

func (*Sink) Name() string

Name implements the name logging reports errors with.

Jump to

Keyboard shortcuts

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