Documentation
¶
Overview ¶
Package log provides logging routines based on slog package.
Package log provides logging routines based on slog package.
Index ¶
- Constants
- Variables
- func Debugf(format string, args ...any)
- func Disable()
- func Errorf(format string, args ...any)
- func Fatalf(format string, args ...any)
- func FromContext(ctx context.Context) *slog.Logger
- func Infof(format string, args ...any)
- func Init(opts ...Option) error
- func IntoContext(ctx context.Context, logger *slog.Logger) context.Context
- func New(enabled bool) logr.Logger
- func NewDefaultLogWriter(level LogLevel) io.Writer
- func Warnf(format string, args ...any)
- type LogLevel
- type Option
- type SubprocessWriter
Constants ¶
const ( DebugLevel = slog.LevelDebug InfoLevel = slog.LevelInfo WarnLevel = slog.LevelWarn ErrorLevel = slog.LevelError )
Variables ¶
var DefaultLogger = slog.Default()
DefaultLogger is the default logger.
Functions ¶
func FromContext ¶
FromContext returns an slog.Logger from the context.
func IntoContext ¶
IntoContext returns a new context with the provided logger.
func NewDefaultLogWriter ¶
NewDefaultLogWriter returns a io.Writer that logs to the given logger at the given level.
Types ¶
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 WithLevelString ¶
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.