log

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package log wrappers slog for the kwok and kwokctl

Index

Constants

View Source
const (
	InfoLevelSecurity  = "info"
	DebugLevelSecurity = "debug"
	WarnLevelSecurity  = "warn"
	ErrorLevelSecurity = "error"
)

The following is Level security definitions.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal() bool

IsTerminal returns true if the given file descriptor is a terminal.

func NewContext

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

NewContext returns a new context with the given logger.

func ToKlogLevel added in v0.2.0

func ToKlogLevel(level Level) int

ToKlogLevel maps the current logging level to a Klog level integer

func ToLogSeverityLevel added in v0.2.0

func ToLogSeverityLevel(level Level) string

ToLogSeverityLevel maps the current logging level to a severity level string

Types

type DurationFormat added in v0.2.0

type DurationFormat struct {
	Nanosecond int64  `json:"nanosecond"`
	Human      string `json:"human"`
}

DurationFormat is the format used to print time.Duration in both nanosecond and string.

type KMetadata

type KMetadata interface {
	GetName() string
	GetNamespace() string
}

KMetadata is a subset of the kubernetes k8s.io/apimachinery/pkg/apis/meta/v1.Object interface this interface may expand in the future, but will always be a subset of the kubernetes k8s.io/apimachinery/pkg/apis/meta/v1.Object interface

type Level

type Level = slog.Level

Level is the logging level.

const (
	LevelDebug Level = slog.LevelDebug
	LevelInfo  Level = slog.LevelInfo
	LevelWarn  Level = slog.LevelWarn
	LevelError Level = slog.LevelError
)

The following is Level definitions copied from slog.

func ParseLevel added in v0.2.0

func ParseLevel(s string) (l Level, err error)

ParseLevel parses a level string.

type Logger

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

Logger is a wrapper around slog.Handler.

func FromContext

func FromContext(ctx context.Context) *Logger

FromContext returns the Logger associated with ctx, or the default logger.

func InitFlags

func InitFlags(ctx context.Context, flags *pflag.FlagSet) (context.Context, *Logger)

InitFlags initializes the flags for the log.

func NewLogger

func NewLogger(w io.Writer, level Level) *Logger

NewLogger returns a new Logger that writes to w.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs a debug message.

func (*Logger) Error

func (l *Logger) Error(msg string, err error, args ...any)

Error logs an error message.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs an informational message.

func (*Logger) Level added in v0.2.0

func (l *Logger) Level() Level

Level returns

func (*Logger) Log

func (l *Logger) Log(level Level, msg string, args ...any)

Log logs a message with the given level.

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs a warning message.

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

With returns a new Logger that includes the given arguments.

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) *Logger

WithGroup returns a new Logger that starts a group. The keys of all attributes added to the Logger will be qualified by the given name.

type ObjectRef

type ObjectRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace,omitempty"`
}

ObjectRef references a kubernetes object

func KObj

func KObj[T KMetadata](obj T) ObjectRef

KObj returns ObjectRef from ObjectMeta

func KObjs

func KObjs[S ~[]T, T KMetadata](s S) []ObjectRef

KObjs returns slice of ObjectRef from an slice of ObjectMeta

func KRef

func KRef(namespace, name string) ObjectRef

KRef returns ObjectRef from name and namespace

func (ObjectRef) String

func (ref ObjectRef) String() string

Jump to

Keyboard shortcuts

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