loki-logger

module
v0.0.0-...-f7cdbce Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT

README

loki-logger

[!WARNING] This library is still in development and is not ready for use. Consider all of the APIs to be unstable.

loki-logger is a simple library for sending logs to a Loki instance from Go. It currently intgrates with log, log/slog, and logr. Note that only the slog impelementation has been tested in any form. Additional logging packages may be added in the future.

Usage

package main

import (
	"context"
	"log/slog"

	"github.com/tslnc04/loki-logger/pkg/client"
	lokislog "github.com/tslnc04/loki-logger/pkg/slog"
)

func main() {
	lokiClient := client.NewLokiClient("http://localhost:3100/loki/api/v1/push")
	logger := lokislog.NewLogger(lokiClient, &slog.HandlerOptions{AddSource: true})
	logger.LogAttrs(context.Background(), slog.LevelInfo, "Hello, world!", slog.Bool("test", true))
}

This repo is licensed under the MIT license. Copyright 2024 Kirsten Laskoski.

Some of the code is based heavily on Promtail, in particular the labelsMapToString function. The original code is licensed under the Apache 2.0 license.

Code has also been taken from the slog package, which is licensed under the BSD 3-clause license. See the LICENSE-go file for details.

Directories

Path Synopsis
pkg
client
Package client provides a client for pushing logs to a Loki instance.
Package client provides a client for pushing logs to a Loki instance.
client/fake
Package fake provides a fake client for testing.
Package fake provides a fake client for testing.
log
Package log provides an io.Writer that writes to a Loki instance.
Package log provides an io.Writer that writes to a Loki instance.
logr
Package logr provides a logr.LogSink implementation that sends log entries to a Loki instance.
Package logr provides a logr.LogSink implementation that sends log entries to a Loki instance.
slog
Package slog implements a slog.Handler that sends logs to a Loki instance.
Package slog implements a slog.Handler that sends logs to a Loki instance.

Jump to

Keyboard shortcuts

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