logutil

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace   = slog.LevelDebug * 2 // trace = double debug
	LevelVerbose = slog.LevelInfo - 1  // verbose = one step more verbose than info
)
View Source
const ErrKey = "err"

ErrKey is the key used for errors in log/slog attributes.

Variables

This section is empty.

Functions

func DescriptorAttrs

func DescriptorAttrs(desc ocispec.Descriptor) []any

DescriptorAttrs formats a descriptor as a list of attributes.

func DescriptorGroup

func DescriptorGroup(desc ocispec.Descriptor) slog.Attr

DescriptorGroup formats an ocispec.Descriptor as a log/slog.Attr.

func ErrAttr

func ErrAttr(err error) slog.Attr

ErrAttr produces a log/slog.Attr for errors.

func FlagErr added in v0.2.0

func FlagErr(name string, err error)

Logs an error when setting up flags.

func OCIPlatformValue

func OCIPlatformValue(plat *ocispec.Platform) slog.Attr

OCIPlatformValue formats an ocispec.Platform as a log/slog.Attr.

func VersionAttrs added in v0.2.0

func VersionAttrs(info version.Info) []slog.Attr

VersionAttrs formats version info as a list of log/slog.Attr.

func WithLogging

func WithLogging(logger *slog.Logger, level slog.Level, opts *oras.CopyGraphOptions) oras.CopyGraphOptions

WithLogging adds logging at level for the OnCopySkipped, PostCopy, and OnMounted functions.

func WithPersistentVerbosityFlags added in v0.2.0

func WithPersistentVerbosityFlags(cmd *cobra.Command, v *VerbosityOptions)

WithPersistentVerbosityFlags adds the debug, quiet, and verbose flags to the given command.

Types

type VerbosityOptions added in v0.2.0

type VerbosityOptions struct {
	Debug   int // number of --debug flags passed
	Quiet   int // number of --quiet flags passed
	Verbose int // number of --verbose flags passed
}

VerbosityOptions configures logger verbosity.

func (*VerbosityOptions) LogLevel added in v0.2.0

func (v *VerbosityOptions) LogLevel(base slog.Level) slog.Level

LogLevel produces the desired slog.Level by parsing the "debug", "verbose", and "quiet" flags.

"base" sets the default level, which gets modified by the flags.

Jump to

Keyboard shortcuts

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