log

package
v0.51.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 14 Imported by: 82

Documentation

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
	LevelFatal = slog.Level(12)
)

Variables

View Source
var (
	String   = slog.String
	Int64    = slog.Int64
	Int      = slog.Int
	Bool     = slog.Bool
	Time     = slog.Time
	Duration = slog.Duration
	Group    = slog.Group
	Any      = slog.Any
)
View Source
var (
	// With calls [Logger.With] on the default logger.
	With = slog.With

	SetDefault = slog.SetDefault

	Debug        = slog.Debug
	DebugContext = slog.DebugContext
	Info         = slog.Info
	InfoContext  = slog.InfoContext
	Warn         = slog.Warn
	WarnContext  = slog.WarnContext
	Error        = slog.Error
	ErrorContext = slog.ErrorContext
)

Functions

func Debugf added in v0.51.0

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

func Err added in v0.51.0

func Err(err error) slog.Attr

Err returns an Attr that represents an error.

func Errorf added in v0.51.0

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

func Fatal

func Fatal(msg string, args ...any)

Fatal for logging fatal errors

func Infof added in v0.51.0

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

func InitLogger

func InitLogger(debug, disable bool)

InitLogger initialize the logger variable

func Prefix added in v0.51.0

func Prefix(prefix string) slog.Attr

Prefix returns an Attr that represents a prefix.

func Warnf added in v0.51.0

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

func WithContextAttrs added in v0.51.0

func WithContextAttrs(ctx context.Context, attrs ...slog.Attr) context.Context

WithContextAttrs returns a new context with the given attrs.

func WithContextPrefix added in v0.51.0

func WithContextPrefix(ctx context.Context, prefix string) context.Context

WithContextPrefix returns a new context with the given prefix.

Types

type ColorHandler added in v0.51.0

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

func NewHandler added in v0.51.0

func NewHandler(out io.Writer, opts *Options) *ColorHandler

func (*ColorHandler) Enabled added in v0.51.0

func (h *ColorHandler) Enabled(_ context.Context, level slog.Level) bool

func (*ColorHandler) Err added in v0.51.0

func (h *ColorHandler) Err(r slog.Record) error

Err returns the error from the attrs, if any.

func (*ColorHandler) Handle added in v0.51.0

func (h *ColorHandler) Handle(ctx context.Context, r slog.Record) error

func (*ColorHandler) Prefix added in v0.51.0

func (h *ColorHandler) Prefix(ctx context.Context, r slog.Record) string

Prefix returns the prefix from the attrs, if any.

func (*ColorHandler) WithAttrs added in v0.51.0

func (h *ColorHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ColorHandler) WithGroup added in v0.51.0

func (h *ColorHandler) WithGroup(name string) slog.Handler

type Logger

type Logger = slog.Logger

Logger is an alias of slog.Logger

func New added in v0.51.0

func New(h slog.Handler) *Logger

New creates a new Logger with the given non-nil Handler.

func WithPrefix added in v0.51.0

func WithPrefix(prefix string) *Logger

WithPrefix calls [Logger.With] with the prefix on the default logger.

Note: If WithPrefix is called within init() or during global variable initialization, it will use the default logger of log/slog package before Trivy's logger is set up. In such cases, it's recommended to pass the prefix via WithContextPrefix to ensure the correct logger is used.

type Options added in v0.51.0

type Options struct {
	// Level reports the minimum level to log.
	// Levels with lower levels are discarded.
	// If nil, the Handler uses [slog.LevelInfo].
	Level slog.Leveler
}

type WriteLogger added in v0.51.0

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

WriteLogger is a wrapper around Logger to implement io.Writer

func NewWriteLogger added in v0.51.0

func NewWriteLogger(logger *Logger) *WriteLogger

NewWriteLogger creates a new WriteLogger

func (*WriteLogger) Write added in v0.51.0

func (l *WriteLogger) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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