log

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package log provides logging routines based on slog package.

Package log provides logging routines based on slog package.

Index

Constants

View Source
const (
	DebugLevel = slog.LevelDebug
	InfoLevel  = slog.LevelInfo
	WarnLevel  = slog.LevelWarn
	ErrorLevel = slog.LevelError
)

Variables

View Source
var DefaultLogger = slog.Default()

DefaultLogger is the default logger.

Functions

func Debugf

func Debugf(format string, args ...any)

Debugf logs a debug message.

func Disable

func Disable()

func Errorf

func Errorf(format string, args ...any)

Errorf logs an error message.

func Fatalf

func Fatalf(format string, args ...any)

Fatalf logs a fatal message.

func FromContext

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

FromContext returns an slog.Logger from the context.

func Infof

func Infof(format string, args ...any)

Infof logs an info message.

func Init

func Init(opts ...Option) error

Init initializes the logger.

func IntoContext

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

IntoContext returns a new context with the provided logger.

func New

func New(enabled bool) logr.Logger

New returns a new logr.Logger. deprecated: Remove usage and this method.

func NewDefaultLogWriter

func NewDefaultLogWriter(level LogLevel) io.Writer

NewDefaultLogWriter returns a io.Writer that logs to the given logger at the given level.

func Warnf

func Warnf(format string, args ...any)

Warnf logs a warning message.

Types

type LogLevel

type LogLevel = slog.Level

type Option

type Option func(*options)

Option is a logger option.

func WithAlsoLogToStderr

func WithAlsoLogToStderr() Option

WithAlsoLogToStderr also logs to stderr.

func WithDevMode

func WithDevMode() Option

WithDevMode sets the logger to development mode. In development mode, the logger logs in human-readable format, the level is set to DebugLevel, and logs are also written to stderr.

func WithJSONOutput

func WithJSONOutput() Option

WithJSONOutput enables JSON-formatted log output.

func WithLevel

func WithLevel(level LogLevel) Option

WithLevel sets the log level. The default log level is InfoLevel.

func WithLevelString

func WithLevelString(level string) Option

WithLevelString sets the log level.

func WithStderrOnly

func WithStderrOnly() Option

WithStderrOnly logs only to stderr, skipping log file creation. Use this for server processes that should not create CLI log files.

type SubprocessWriter

type SubprocessWriter struct {
	Source string   // e.g., "envoy", "coredns"
	Level  LogLevel // Log level for the output
	// contains filtered or unexported fields
}

SubprocessWriter wraps subprocess output lines as structured log entries. Each line from the subprocess is emitted as a separate log entry with the given source name and log level.

func NewSubprocessWriter

func NewSubprocessWriter(source string, level LogLevel) *SubprocessWriter

NewSubprocessWriter creates a new SubprocessWriter.

func (*SubprocessWriter) Write

func (w *SubprocessWriter) Write(p []byte) (n int, err error)

Write implements io.Writer. It buffers input and logs complete lines.

Jump to

Keyboard shortcuts

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