slogger

package module
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: Apache-2.0 Imports: 9 Imported by: 6

README

go-kit/slogger

Go Reference GitHub Release GoCard GitHub license

Требования

  • поля со значениями, а не строки
  • в числе полей есть имя файла и номер строки
  • в проде поля пишутся в json
  • при отладке в консоли - читаемый вывод
  • для тестов вывод пишется в буфер и его можно анализировать
  • ?? возможность влючить отладку заданного пакета

TODO

примеры (narra? webtail?)

Documentation

Index

Constants

View Source
const TimeDisableKey = " "

TimeDisableKey removes time from the output.

Variables

View Source
var LogLevel = new(slog.LevelVar) // The zero LevelVar corresponds to [LevelInfo].

LogLevel holds

Functions

func ErrAttr added in v0.12.24

func ErrAttr(err error) slog.Attr

ErrAttr returns slog.Attr for err value.

func FromContext added in v0.15.0

func FromContext(ctx context.Context) *slog.Logger

FromContext returns the logger from the provided context. If no logger it returns the default logger.

func LogLevelSet added in v0.14.0

func LogLevelSet(lvl slog.Level)

LogLevelSet updates the application log level.

func LogLevelSwitch added in v0.14.0

func LogLevelSwitch()

LogLevelSwitch switches the application log level between Debug and Info.

func NewContext added in v0.15.0

func NewContext(ctx context.Context, logger *slog.Logger) context.Context

NewContext returns a new context with the provided logger.

func Setup

func Setup(cfg Config, out io.Writer) error

Setup creates slog default logger.

Types

type Config

type Config struct {
	Debug  bool   `long:"debug" description:"Show debug info"  env:"DEBUG"`
	Format string `` //lint:ignore SA5008 accepted as correct
	/* 131-byte string literal not displayed */
	TimeFormat  string `description:"Time format for text output" long:"time_format" env:"TIME_FORMAT" default:"2006-01-02 15:04:05.000"`
	Destination string `description:"Log destination (default: '', means STDERR)" long:"dest" env:"DEST"`
}

Config holds package configuration.

Jump to

Keyboard shortcuts

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