package promslog

import "github.com/prometheus/common/promslog"

Index

Variables

var (
	// LevelFlagOptions represents allowed logging levels.
	LevelFlagOptions = []string{"debug", "info", "warn", "error"}
	// FormatFlagOptions represents allowed formats.
	FormatFlagOptions = []string{"logfmt", "json"}
)

Functions

func New

func New(config *Config) *slog.Logger

New returns a new slog.Logger. Each logged line will be annotated with a timestamp. The output always goes to stderr.

func NewNopLogger

func NewNopLogger() *slog.Logger

NewNopLogger is a convenience function to return an slog.Logger that writes to io.Discard.

Types

type Config

type Config struct {
	Level  *Level
	Format *Format
	Style  LogStyle
	Writer io.Writer
}

Config is a struct containing configurable settings for the logger

type Format

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

Format controls a logging output format. Not concurrency-safe.

func NewFormat

func NewFormat() *Format

NewFormat creates a new Format.

func (*Format) Set

func (f *Format) Set(s string) error

Set updates the value of the allowed format.

func (*Format) String

func (f *Format) String() string

type Level

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

Level controls a logging level, with an info default. It wraps slog.LevelVar with string-based level control. Level is safe to be used concurrently.

func NewLevel

func NewLevel() *Level

NewLevel returns a new Level.

func (*Level) Set

func (l *Level) Set(s string) error

Set updates the logging level with the validation.

func (*Level) String

func (l *Level) String() string

String returns the current level.

func (*Level) UnmarshalYAML

func (l *Level) UnmarshalYAML(unmarshal func(interface{}) error) error

type LogStyle

type LogStyle string

LogStyle represents the common logging formats in the Prometheus ecosystem.

const (
	SlogStyle  LogStyle = "slog"
	GoKitStyle LogStyle = "go-kit"
)

Source Files

slog.go

Directories

PathSynopsis
promslog/flag
Version
v0.63.0 (latest)
Published
Mar 13, 2025
Platform
linux/amd64
Imports
8 packages
Last checked
2 hours ago

Tools for package owners.