log

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const TraceLevel = slog.LevelDebug - 1

TraceLevel is the logging level when set to Trace verbosity.

Variables

This section is empty.

Functions

func SlogLevelToLogrusLevel

func SlogLevelToLogrusLevel(level slog.Level) logrus.Level

SlogLevelToLogrusLevel converts a slog.Level to its equivalent logrus.Level.

func ValidateFields

func ValidateFields(formatInput []string) (result []string, err error)

Types

type JSONFormatter

type JSONFormatter struct {
	logrus.JSONFormatter

	ExtraFields []string
	// FormatCaller is a function to return (part) of source file path for output.
	// Defaults to filePathAndLine() if unspecified
	FormatCaller func() (caller string)
	// contains filtered or unexported fields
}

JSONFormatter implements the logrus.Formatter interface and adds extra fields to log entries.

func NewTestJSONFormatter

func NewTestJSONFormatter() *JSONFormatter

NewTestJSONFormatter creates a JSONFormatter that is configured for output in tests.

func (*JSONFormatter) CheckAndSetDefaults

func (j *JSONFormatter) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets log format configuration.

func (*JSONFormatter) Format

func (j *JSONFormatter) Format(e *logrus.Entry) ([]byte, error)

Format formats each log line as configured in teleport config file.

type SharedWriter

type SharedWriter struct {
	io.Writer
	// contains filtered or unexported fields
}

SharedWriter is an io.Writer implementation that protects writes with a mutex. This allows a single io.Writer to be shared by both logrus and slog without their output clobbering each other.

func NewSharedWriter

func NewSharedWriter(w io.Writer) *SharedWriter

NewSharedWriter wraps the provided io.Writer in a writer that is thread safe.

func (*SharedWriter) Write

func (s *SharedWriter) Write(p []byte) (int, error)

type SlogJSONHandler

type SlogJSONHandler struct {
	*slog.JSONHandler
}

SlogJSONHandler is a slog.Handler that outputs messages in a json format per the config file.

func NewSlogJSONHandler

func NewSlogJSONHandler(w io.Writer, cfg SlogJSONHandlerConfig) *SlogJSONHandler

NewSlogJSONHandler creates a SlogJSONHandler that outputs to w.

type SlogJSONHandlerConfig

type SlogJSONHandlerConfig struct {
	// Level is the minimum record level that will be logged.
	Level slog.Leveler
	// ConfiguredFields are fields explicitly set by users to be included in
	// the output message. If there are any entries configured, they will be honored.
	// If empty, the default fields will be populated and included in the output.
	ConfiguredFields []string
	// ReplaceAttr is called to rewrite each non-group attribute before
	// it is logged.
	ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}

SlogJSONHandlerConfig allow the SlogJSONHandler functionality to be tweaked.

type SlogTextHandler

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

SlogTextHandler is a slog.Handler that outputs messages in a textual manner as configured by the Teleport configuration.

func NewSlogTextHandler

func NewSlogTextHandler(w io.Writer, cfg SlogTextHandlerConfig) *SlogTextHandler

NewSlogTextHandler creates a SlogTextHandler that writes messages to w.

func (*SlogTextHandler) Enabled

func (s *SlogTextHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns whether the provided level will be included in output.

func (*SlogTextHandler) Handle

func (s *SlogTextHandler) Handle(ctx context.Context, r slog.Record) error

Handle formats the provided record and writes the output to the destination.

func (*SlogTextHandler) WithAttrs

func (s *SlogTextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs clones the current handler with the provided attributes added to any existing attributes. The values are preformatted here so that they do not need to be formatted per call to Handle.

func (*SlogTextHandler) WithGroup

func (s *SlogTextHandler) WithGroup(name string) slog.Handler

WithGroup opens a new group.

type SlogTextHandlerConfig

type SlogTextHandlerConfig struct {
	// Level is the minimum record level that will be logged.
	Level slog.Leveler
	// EnableColors allows the level to be printed in color.
	EnableColors bool
	// Padding to use for various components.
	Padding int
	// ConfiguredFields are fields explicitly set by users to be included in
	// the output message. If there are any entries configured, they will be honored.
	// If empty, the default fields will be populated and included in the output.
	ConfiguredFields []string
	// ReplaceAttr is called to rewrite each non-group attribute before
	// it is logged.
	ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}

SlogTextHandlerConfig allow the SlogTextHandler functionality to be tweaked.

type TextFormatter

type TextFormatter struct {
	// ComponentPadding is a padding to pick when displaying
	// and formatting component field, defaults to DefaultComponentPadding
	ComponentPadding int
	// EnableColors enables colored output
	EnableColors bool
	// FormatCaller is a function to return (part) of source file path for output.
	// Defaults to filePathAndLine() if unspecified
	FormatCaller func() (caller string)
	// ExtraFields represent the extra fields that will be added to the log message
	ExtraFields []string
	// contains filtered or unexported fields
}

TextFormatter is a logrus.Formatter that outputs messages in a textual format.

func NewDefaultTextFormatter

func NewDefaultTextFormatter(enableColors bool) *TextFormatter

NewDefaultTextFormatter creates a TextFormatter with the default options set.

func (*TextFormatter) CheckAndSetDefaults

func (tf *TextFormatter) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets log format configuration.

func (*TextFormatter) Format

func (tf *TextFormatter) Format(e *logrus.Entry) ([]byte, error)

Format formats each log line as configured in teleport config file.

Jump to

Keyboard shortcuts

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