promtail

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 5 Imported by: 1

README

promtail golang client

The purpose of this small library is creating a tool for upload logs to grafana loki. The logs looks pretty amazing and awesome, we can have static labels or dynamic labels for filtering while we're debugging.

awesome_logs

promtail client for golang services

// create a promtail client
promtail, pErr := client.NewSimpleClient(host, username, password,
    client.WithStaticLabels(map[string]interface{}{
        "app": "awesome-service",
    }),
    client.WithStreamConverter(promtail.NewRawStreamConv(labels, "=")),
)
if pErr != nil {
    panic(pErr)
}

// now can be used as a Writer for any logger

// setup any logger and use as the output, can be combined with many outputs using io.MultiWriter
output := zerolog.ConsoleWriter{Out: promtail}
output.FormatMessage = func(i interface{}) string {
    _, ok := i.(string)
    if ok {
        return fmt.Sprintf("%-50s", i)
    } else {
        return ""
    }
}
output.FormatLevel = func(i interface{}) string {
    _, ok := i.(string)
    if ok {
        return fmt.Sprintf("level=%-7s", i)
    } else {
        return "level=info"
    }
}
log.Logger = log.Output(output)

log.Info().
    Str("my_label", "some_value").
    Msg("the message")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry []interface{}

type HttpClient

type HttpClient interface {
	Push(ctx context.Context, request PushRequest) error
}

type LabelSet

type LabelSet map[string]interface{}

LabelSet is a key/value pair mapping of labels

type PushRequest

type PushRequest struct {
	Streams []*Stream `json:"streams"`
}

PushRequest models a log stream push

type Stream

type Stream struct {
	Labels  LabelSet `json:"stream"`
	Entries []Entry  `json:"values"`
}

Stream represents a log stream. It includes a set of log entries and their labels.

type StreamConverter

type StreamConverter interface {
	ConvertEntry([]byte) (Entry, error)
	ExtractLabels([]byte) (LabelSet, error)
}

func NewRawStreamConv

func NewRawStreamConv(labels, sep string) StreamConverter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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