Skip to content

Experimental Go library for logging directly to Loki

License

MIT, BSD-3-Clause licenses found

Licenses found

MIT
LICENSE
BSD-3-Clause
LICENSE-go
Notifications You must be signed in to change notification settings

tslnc04/loki-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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))
}

Copyright

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.

About

Experimental Go library for logging directly to Loki

Resources

License

MIT, BSD-3-Clause licenses found

Licenses found

MIT
LICENSE
BSD-3-Clause
LICENSE-go

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages