loki

package
v0.0.0-...-ec6f880 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

README

git.frostfs.info/TrueCloudLab/frostfs-observability/loki"

A simple asynchronous client in Go for sending logs to Loki.

Usage

package main

import (

	"time"

	"git.frostfs.info/TrueCloudLab/frostfs-observability/logging/lokicore/loki"
)

func main() {
	loki := loki.Setup(loki.Config{
		Address: "localhost:3100/api/prom/push",
		Labels: map[string]string{
			"label": "test",
		},
		BatchWait:          1000,
		BatchEntriesNumber: 200,
		Enabled:            true,
	})
    defer loki.Shutdown()

    loki.Send("log message", time.Now())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a client for sending log entries.

func Setup

func Setup(conf Config) *Client

Setup initializes the client with the given configuration and starts the processing goroutine. It is the caller's responsibility to call Shutdown() to free resources.

func (*Client) IsEnabled

func (client *Client) IsEnabled() bool

IsEnabled checks whether the client is enabled.

func (*Client) Send

func (client *Client) Send(msg string, timestamp time.Time) error

Send sends the message to the loki server. If the client is disabled, it returns error. If the entries channel is full, the message is discarded and returns error.

func (*Client) Shutdown

func (client *Client) Shutdown()

Shutdown stops the client and waits for all logs to be sent.

type Config

type Config struct {
	Enabled bool
	// E.g. localhost:3100/api/prom/push.
	Endpoint string
	Labels   map[string]string
	// Maximum message buffering time.
	BatchWait time.Duration
	// Maximum number of messages in the queue.
	BatchEntriesNumber int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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